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

nodejs-gas-bundler

v1.0.0

Published

Node.js bundler for Google Apps Script

Readme

Node.js Bundler for Google Apps Script

npm version License: MIT Build Status

A powerful tool that bundles Node.js modules (including NPM packages) into a single JavaScript file compatible with Google Apps Script (GAS). This enables you to use thousands of NPM libraries directly in your Google Apps Script projects.

The tool can be used in command-line, or programatically as a library with Rollup.

📦 Installation

Global Installation (Recommended)

npm install -g nodejs-gas-bundler

Local Installation

npm install nodejs-gas-bundler --save-dev

Using npx (No Installation Required)

npx nodejs-gas-bundler --help

🎯 Quick Start

1. Create Your Entry Point

Create an index.js file that exports what you want to use in Google Apps Script:

// Export your own functions
export function add(x, y) {
  return x + y;
}

export function subtract(x, y) {
  return x - y;
}

// Export from NPM packages
export { marked } from 'marked';

2. Install Dependencies

npm init -y
npm install marked

3. Bundle for Google Apps Script

To generate the Google Apps Script bundle into bundle.js, run:

bundle-for-gas -i index.js -o bundle.js -n MyLib

With the -n MyLib option, all the definitions will be added to a top-level object MyLib. If you prefer the definitions to be added to the global object, you can use the -g option instead:

bundle-for-gas -i index.js -o bundle.js -g

This is especially useful if you intend to use the generated bundled as a library within Google Apps Script projects.

4. Import and use in Google Apps Script

Copy the generated bundle.js content into your Google Apps Script project and use it:

// If you used -n MyLib
const result = MyLib.add(5, 3);
const html = MyLib.marked('# Hello World');

// If you used -g flag
const result = add(5, 3);
const html = marked('# Hello World');

You can also upload your bundled code to Google Apps Script using the clasp command-line tool. For improved organization and easy reuse, consider publishing your bundle as a Google Apps Script library. This approach makes it simple to share your code and use it across multiple Apps Script projects.

📖 Usage

Command-line interface

Basic Syntax

bundle-for-gas -i <input> -o <output> [options]

Options

| Option | Alias | Description | Default | |--------|-------|-------------|---------| | --input | -i | Path to source JavaScript file | Required | | --output | -o | Path to output bundle file | Required | | --global-name | -n | Name of the global variable | '' | | --merge-into-global | -g | Merge exports into global object | false | | --help | -h | Show help information | - |

Examples

Basic Bundle with Namespace
bundle-for-gas -i src/index.js -o dist/bundle.js -n MyLibrary
Global Variable Exposure
bundle-for-gas -i src/index.js -o dist/bundle.js -g
Combined Options
bundle-for-gas -i src/index.js -o dist/bundle.js -n MyLib -g

Library

You can also use this package as a library in your build scripts:

import { createRollupConfig } from 'nodejs-gas-bundler';
import { rollup } from 'rollup';

async function myBundle() {
  const config = createRollupConfig({
    inputFile: 'src/index.js',
    outputFile: 'dist/bundle.js',
    globalName: 'MyLibrary',
    mergeIntoGlobal: false
  });
  
  const bundle = await rollup(config);
  await bundle.write(config.output);
}

myBundle().catch(console.error);

The above process is encapsulated in the bundle function:

import { bundle } from 'nodejs-gas-bundler';

bundle({
  inputFile: 'src/index.js',
  outputFile: 'dist/bundle.js',
  globalName: 'MyLibrary',
  mergeIntoGlobal: false
}).catch(console.error);

Full example

A full example is available in the examples directory. This example bundles two popular NPM libraries:

  • csv-parse (a CSV parser),
  • marked (a Markdown parser)

and uploads them in an existing Google Apps Script using clasp. You can see the resulting project here.

⚠️ Limitations & Considerations

Google Apps Script Environment

  • No Node.js APIs: Node.js-specific modules won't work (fs, path, etc.)
  • Memory Limits: Large bundles may hit GAS memory limits
  • Execution Time: Complex operations may timeout

Polyfills

The bundler includes basic polyfills for common Node.js globals, but some packages may require additional configuration.

🙏 Credits

This project uses the following open source tools:

  • Rollup – for JavaScript bundling
  • Babel – for JavaScript transpilation

📝 TODOs

  • Polyfill for fetch using UrlFetchApp