Skip to content
Apps Script Example project with npm modules
Branch: master
Clone or download
Latest commit 0844990 Mar 27, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
server initial commit of the code Mar 26, 2019
.gitignore initial commit of the code Mar 26, 2019
LICENSE Initial commit Mar 26, 2019 Update Mar 27, 2019
appsscript.json initial commit of the code Mar 26, 2019
package.json initial commit of the code Mar 26, 2019
webpack.gas.js initial commit of the code Mar 26, 2019

Using npm modules in Google Apps Script

An example project where we bundle npm modules and use ES6 code in Google Apps Script

See the full article here


Install clasp command line tool

npm install @google/clasp -g

Then login to your Google account

clasp login

Open terminal and clone this project.

You have to create an Apps Script project to run this code.

clasp create --type standalone --title "Apps Script with Webpack and babel"

Now build the project and upload to your newly created Apps Script project

npm install
npm run deploy

Why use npm in Apps Script?

Google Apps Script is quite powerful since it can access other Google services like Google Sheets, Gmail and Google docs. You can take automation to the next level using Google Aps Script.

Being able to use npm modules will make creating and sharing re-usable modules quite easy. This will make it easy to create wrappers for popular services and use those services in your Apps Script project.

In this example project, we are using momentjs and lodash in the Apps Script project.

How is it done?

See the server/lib.js file. It imports the npm module and exports functions that use the imported packages. The api.js has a global function doGet() which gets called by Apps Script to show the web page. If you see the webpack.config.js file, notice that the bundle exposes a global variable AppLib where you can get the functions exported in the bundle.

Follow the complete article here


The author does not represent nor associated with Google in any way. This is project is only for learning purposes.

You can’t perform that action at this time.