Hi all,
I’m at my wits end. I’ve written code for Airtable locally, which largely works. Now I’d like to place the code on a cloud functions tool so I can run my code on the browser and have it communicate with other APIs.
Here’s the code I have on the serverless tool, just the basics first just trying to call the airtable library.
/**
* main() will be run when you invoke this action
*
* @param Cloud Functions actions accept a single parameter, which must be a JSON object.
*
* @return The output of this action, which must be a JSON object.
*
*/
var Airtable = new require('airtable');
var base = new Airtable({apiKey: 'XXXXXXXXXXXXX'}).base('appumWMhUzhgN8fFe');
function main(params) {
return { message: 'Hello World' };
}
When I try to run this code, I get
Error: Cannot find module ‘airtable’\n
In this case I’m using IBM Cloud Functions, but the process as I also read Google Cloud Functions and others seems to be the same. I just am doing something wrong. Here’s the link to the docs
https://cloud.ibm.com/docs/openwhisk?topic=openwhisk-prep#prep_js_npm
Here are the steps I’ve taken.
- I create a new folder in my directory called “package-airtable”. I copy the “airtable” folder from j_mai > node_modules > airtable, into the “package-airtable” folder. So I have a new folder in “j_mai > package-airtable” with the airtable folder you see below.
- I then create a package.json file in the folder “package-airtable” with the name: “my-action” and “dependencies” “airtable”: “^0.10.1”
{
"name": "my-action",
"dependencies" : {
"airtable": "^0.10.1"
}
}
//contents of my package.json
- Then I create a zip folder, called “action.zip” with the package.json and the “airtable” library.
- Finally, I upload the zip file to the default package using this code on the command line.
$ ibmcloud fn action create package-airtable action.zip --kind nodejs:10
You can see here the “package-airtable” gets created.
To test
- I’m not sure if I’m supposed to, but I click “Invoke” on the “package-airtable” and I get an error message about not being able to find a module nodejsAction.
- If I go back to my “airtabledefaultest”, I run into the same error at the beginning, "Cannot find module ‘airtable’\n.
Any help would be greatly appreciated!