npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodejs-helpers

v1.1.9

Published

A set of classes to simplify interaction with Google Apis.

Downloads

33

Readme

Node.js Helpers

Codacy Badge codebeat badge dependencies Status devDependencies Status Known Vulnerabilities

A set of classes to simplify interaction with Google Apis.

Table of Contents

Setup

  1. Install Node.js v8.9.2 or greater

  2. Set the GCLOUD_PROJECT environment variable:

    Linux:

     export GCLOUD_PROJECT=your-project-id

    Windows:

     set GCLOUD_PROJECT=your-project-id

    Windows (PowerShell):

     $env:GCLOUD_PROJECT="your-project-id"
  3. Obtain authentication credentials.

    Create local credentials by running the following command and following the oauth2 flow (read more about the command here):

     gcloud auth application-default login

    In non-Google Cloud environments, GCE instances created without the correct scopes, or local workstations where the gcloud beta auth application-default login command fails, use a service account by doing the following:

    • Go to API Manager -> Credentials
    • Click "New Credentials", and create a service account or click here
    • Download the JSON for this service account, and set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to the file containing the JSON credentials.

    Set the GOOGLE_APPLICATION_CREDENTIALS environment variable:

    Linux:

     export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json

    Windows:

     set GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account_file.json

    Windows (PowerShell):

     $env:GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_account_file.json"

    Note for code running on GCE, GAE, or other environments:

    On Google App Engine, the credentials should be found automatically.

    On Google Compute Engine, the credentials should be found automatically, but require that you create the instance with the correct scopes.

     gcloud compute instances create --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/compute,https://www.googleapis.com/auth/compute.readonly" test-instance

    If you did not create the instance with the right scopes, you can still upload a JSON service account and set GOOGLE_APPLICATION_CREDENTIALS as described.

    Read more about Google Cloud Platform Authentication.

How to use

MessageTransport

Using Promises

const { MessageTransport } = require("nodejs-helpers");

const topicName = "test-jal",
  data = { jal: "test" },
  attributes = { attr1: "1", attr2: "2" },
  transport = new MessageTransport(topicName);
transport.publish(data, attributes)
  .then((response) => {
    console.log(response);
    // 45031755284181 // messageId of the published message
  })
  .catch((err) => {
    console.error(err);
  });

Using async/await

const { MessageTransport } = require("nodejs-helpers");

async function testMessageTransport() {
  try {
    const topicName = "test-jal",
      data = { jal: "test" },
      attributes = { attr1: "1", attr2: "2" }
    const transport = new MessageTransport(topicName);
    const response = await transport.publish(data, attributes);
    console.log(response);
    // 45031755284181 // messageId of the published message
  } catch (err) {
    console.error(err);
  }
}

(async() => {
  await testMessageTransport();
})();

StorageProvider

Using Promises

const { StorageProvider } = require("nodejs-helpers");

const storage = new StorageProvider({
  forBigQuery: true,
  bucketName: "now-ims-core-dev_bigquery-staging"
});

storage.save("test_jal/jal.txt", "hey")
  .then((response) => {
    console.log(response);
    // { success: true, payload: '"h"\n"e"\n"y"' }
  })
  .catch((err) => {
    console.error(err);
  });

storage.save("test_jal/jal.txt", "hey", { forBigQuery: false })
  .then((response) => {
    console.log(response);
    // { success: true, payload: 'hey' }
  })
  .catch((err) => {
    console.error(err);
  });

Using async/await

const { StorageProvider } = require("nodejs-helpers");

async function testStorageProvider() {
  try {
    const storage = new StorageProvider({
      forBigQuery: true,
      bucketName: "my-testing-bucket"
    });

    let response = await storage.save("test_jal/jal.txt", "hey");
    console.log(response);
    // { success: true, payload: '"h"\n"e"\n"y"' }

    response = await storage.save("test_jal/jal.txt", "hey", { forBigQuery: false });
    console.log(response);
    // { success: true, payload: 'hey' }
  } catch (err) {
    console.error(err);
  }
}

(async() => {
  await testStorageProvider();
})();

Logger

const { Logger } = require("nodejs-helpers");
const logger = new Logger();

logger.debug("debug");
// 2018-02-28T05:21:53.214Z - debug: debug
logger.info("info");
// 2018-02-28T05:21:53.217Z - info: info
logger.error("error");
// 2018-02-28T05:21:53.218Z - error: error