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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gbatchrequests

v1.0.0

Published

This is a Node.js module to run the batch requests of Google APIs.

Readme

node-gbatchrequests

MIT License

Overview

This is a Node.js module to run the batch requests of Google APIs.

Description

In Google APIs, there are APIs where batch requests can be run. The batch requests can run multiple API calls by one API call with the asynchronous process. By this, both the process cost and the quota cost can be reduced. Ref In Node.js, the wonderful module of googleapis for Node.js is existing. But, in the current stage, unfortunately, it seems that the googleapis for Node.js cannot run the batch requests. Ref So, I created this module. This module can achieve batch requests with Node.js. In order to run batch requests, the access token retrieved from googleapis for Node.js can be used.

Install

$ npm install --save-dev gbatchrequests

or

$ npm install --global gbatchrequests

You can also see this module at https://www.npmjs.com/package/gbatchrequests.

Method

| Method | Explanation | | :----------------------------------- | :--------------------------------- | | RunBatch(obj) | Run batch requests of Google APIs. | | GetBatchPath(obj) | Get batch path. |

This library uses HTTPS for requesting Google APIs.

Usage

About the authorization, please check the section of Authorization.

Scopes

This library requests your inputted requests as batch requests. So, the requirement scopes depend on the Google APIs you want to use. So, please check the official document of the API you want to use.

1. RunBatch(obj)

This is the main method of this library. This method runs the batch requests of Google APIs.

Sample script

This is a sample script for changing the filename of a file on Google Drive using batch requests.

const { RunBatch } = require("gbatchrequests");

const fileId = "###"; // Please set the file ID.
const obj = {
  accessToken: "###", // Please set your access token.
  api: { name: "drive", version: "v3" },
  requests: [
    {
      method: "PATCH",
      endpoint: `https://www.googleapis.com/drive/v3/files/${fileId}`,
      requestBody: { name: "sample" },
    },
  ],
};
RunBatch(obj)
  .then((res) => console.log(res))
  .catch((err) => console.error(err));
  • accessToken: (Required) Your access token. In this case, please include the scopes you want to use.
  • api: { name: "###", version: "###" }: (Required) Please set the API name and the API version you want to use. For example, when Drive API is used, it's api: { name: "drive", version: "v3" }. When version is not used, the latest version is automatically used.
  • requests: (Required) Please set method, endpoint, and requestBody of Google API you want to use. For example, when you want to change the filename of the file on Google Drive, the above sample script can be used.
  • skipError: (Option) When this is true, even when an error occurs in the request, the error is skipped. The default is false. So, when an error occurs, the script is stopped.
  • returnRawData: (Option) In the case of batch requests, the returned values are text data as the default. When this option is true, the returned value is not parsed. Namely, you can retrieve the raw text data. The default is false. So, as the default, the returned values are parsed.

2. GetBatchPath(obj)

Get batch path. The batch path is required to be used from August 12, 2020. Ref For example, when Drive API is used with the batch requests, the batch path is batch/drive/v3.

Sample script

In this case, batch/drive/v3 is obtained as the response value.

const { GetBatchPath } = require("gbatchrequests");

const obj = { api: { name: "drive", version: "v3" } };
GetBatchPath(obj)
  .then((res) => console.log(res))
  .catch((err) => console.error(err));
  • api: { name: "###", version: "###" }: (Required) Please set the API name and the API version you want to use. For example, when Drive API is used, it's api: { name: "drive", version: "v3" }. When version is not used, the latest version is automatically used.

Limitations for batch request

There are some limitations to the batch request.

About how to retrieve access token

Retrieving access token from OAuth2 with Quickstart

When Quickstart of Node.js for Drive API is seen, you can see const drive = google.drive({version: 'v3', auth: authClient});. Ref In this sample, the access token is retrieved from authClient.

const accessToken = authClient.credentials.access_token;

Retrieving access token from Service account

When the access token is retrieved from the service account, you can retrieve the access token using the following script.

const accessToken = await new google.auth.GoogleAuth({
  keyFile: "### file path of service account credential file ###",
  scopes: ["### Scopes you want to use ###"],
}).getAccessToken();

Licence

MIT

Author

Tanaike

If you have any questions and commissions for me, feel free to tell me.

Update History

  • v1.0.0 (October ##, 2022)

    1. Initial release.

TOP