1

I'm working on the IBM Cloud (browser UI), created the hello world action and added these three lines:

const fs = require('fs'); 
const readline = require('readline'); 
const {google} = require('googleapis');

The third line throws an error

Initialization has failed due to: Error: Cannot find module 'googleapis'

I wonder how I can install Node.js modules like googleapis to avoid this error.

jpsstack
  • 1,221
  • 4
  • 18
  • 29

1 Answers1

2

Locally, you will want to npm install the module you want to use. Then when you deploy, you zip up the entire directory, and use the CLI to deploy the zip file, not the JS file.

This is documented further here: https://cloud.ibm.com/docs/openwhisk?topic=cloud-functions-prep#prep_js_npm

And my old blog post: https://www.raymondcamden.com/2017/01/10/creating-packaged-actions-in-openwhisk (although my post uses the older CLI though)

Also note that their platform ships with a bunch of npm modules built in - you can see the list here: https://cloud.ibm.com/docs/openwhisk?topic=cloud-functions-runtimes#openwhisk_ref_javascript_environments

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68