CloudCode Dependencies

Defaults

A few npm packages are included by default in every task. This includes:
  • aws-sdk
  • node-fetch (exposed as a fetch global function)
Additional npm dependencies can be added to a task via OXIDE:
  1. 1.
    Right-click on the specific CloudCode task
  2. 2.
    Select Add Node.js package
  3. 3.
    Search for the package you'd like to add and select it.

Private NPM Packages

CloudCode supports the addition of private NPM packages to be used in tasks. To do this, you need to:
  1. 1.
    Update the package.json file with the relevant details for the private package you are using.
  2. 2.
    Add an access token for your org in the task's .npmrc file. To do this, open the task's .npmrc file and add this line: //registry.npmjs.org/:_authToken=$NPM_TOKEN - where $NPM_TOKEN is your NPM user's access token.
  3. 3.
    Update the yarn.lock file (right-click on the task on OXIDE).

Using dependencies

Once dependencies are added to the task, they can be imported and used in the task:
import * as Rollbar from 'rollbar';
const rollbar = new Rollbar({
accessToken: process.env.POST_SERVER_ITEM_ACCESS_TOKEN,
captureUncaught: true,
captureUnhandledRejections: true
}); // Read more about process.env in our Enviroment variable docs.
export async function run() {
try {
let res = await fetch('https://www.journeyapps.com')
if (res.ok) {
rollbar.info("Fetched www.journeyapps.com");
} else {
throw new Error(`request to https://www.journeyapps.com failed, reason: ${res.status} ${res.statusText}`);
}
} catch (err) {
rollbar.error(`Unable to fetch https://www.journeyapps.com got '${err.message}'`, err);
}
}

How to manage dependencies in OXIDE:

The following doc details how to manage CloudCode dependencies in OXIDE.
Copy link
On this page
Defaults
Private NPM Packages
Using dependencies
How to manage dependencies in OXIDE: