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

sheetsfunc

v1.0.0

Published

## Overview

Downloads

0

Readme

Google Sheets as Function NPM Module

Overview

This NPM module allows developers to use Google Sheets as a function in their JavaScript/Node.js projects. The module leverages the Google Sheets API to take input in specific cells, perform operations within the sheet, then read and return results from specified output cells.

When it can be helpful

This module can be particularly useful when you want to leverage the capabilities of Google Sheets within your Node.js application. For example:

  • Complex calculations: Google Sheets supports a wide range of functions and formulas for performing complex calculations, which you can use without having to implement them in your own code.
  • Data transformation: Google Sheets has several built-in tools and functions for transforming data, such as parsing dates or manipulating text.
  • Collaborative scenarios: Google Sheets enables real-time collaboration, so you can use it as a shared platform for inputting or manipulating data.

Risks

  • API quota: Google Sheets API has usage limits. Exceeding these limits could lead to service interruptions.
  • Performance: Network latency and the time required to process data in Google Sheets can impact performance. It's not suitable for scenarios that require real-time response.
  • Security: The module uses a service account for authentication, and you need to securely manage its credentials.

Scalability issues

  • Google Sheets limitations: A single Google Sheet has a maximum limit of 5 million cells. In addition, Google Sheets may not perform well with very large sheets.
  • Rate limiting: The Google Sheets API has rate limiting. Sending too many requests in a short period can result in some requests being denied.

Example Usage

const SheetsFunc = require('./sheetsfunc');

async function main() {
  const sheetsUrl = 'https://docs.google.com/spreadsheets/d/YOUR_SPREADSHEET_ID/edit#gid=0';
  const authFile = '/path/to/your/service-account-json-file.json';
  
  const inputs = {"input_name":"Sheet1!A1","input_other_name":"Sheet1!A2"};
  const outputs = {"output_name":"Sheet1!B1:B2","output_other_name":"Sheet2!B3"};
  
  const myFunction = await SheetsFunc.createSheetsFunction(sheetsUrl, authFile, inputs, outputs);
  
  const inputDict = {"input_name":[['Hello']], "input_other_name":[['World']]};
  const outputDict = await myFunction(inputDict);
  
  console.log(outputDict);
}

main();

Replace 'YOUR_SPREADSHEET_ID' with the ID of your Google Sheets spreadsheet, 'Sheet1!A1', 'Sheet1!A2', 'Sheet1!B1:B2', and 'Sheet2!B3' with the cell ranges you want to write to and read from, and '/path/to/your/service-account-json-file.json' with the path to your Google Service Account JSON file. The inputDict should be a dictionary mapping input names to 2D arrays representing the data you want to write to Google Sheets.

Conclusion This module provides an easy way to leverage the power of Google Sheets in your Node.js applications. However, it's essential to consider the risks and scalability issues when deciding whether it's the right solution for your use case.

Creating a Google Service Account

1. Go to the Google Cloud Console

Visit the Google Cloud Console at https://console.cloud.google.com.

2. Create a new project

Click on the project dropdown and select "New Project". Enter a project name, then click "Create".

3. Enable the Google Sheets API

With your new project selected, click "Dashboard" on the left-hand sidebar, then click "+ Enable APIs and Services" at the top of the page. In the API Library, search for "Google Sheets API" and click on it, then click "Enable".

4. Create a Service Account

Go back to the dashboard, click "IAM & Admin" in the left-hand sidebar, then click "Service accounts". Click "+ Create Service Account" at the top of the page.

Enter a name and description for your service account, then click "Create".

5. Grant Permissions

On the "Service account permissions" page, in the "Select a role" dropdown, select "Project" -> "Editor", then click "Continue".

6. Create a JSON Key

Click "+ Create Key" on the "Grant users access to this service account" page. Select "JSON" as the key type, then click "Create".

This will download a JSON key file to your computer. Keep this file secure, as it contains sensitive information.

7. Enable Sheets API Access

Finally, you need to share your Google Sheets with the service account.

Open the JSON key file and find the "client_email" field. Copy the email address (which should look something like <name>@<project-id>.iam.gserviceaccount.com).

Open your Google Sheets in a browser and click the "Share" button. Paste the service account email into the "People" field, then click "Done".

Your service account is now set up and can access the Google Sheets API with the permissions of the Google Sheets you shared with it.