CloudCode Dependencies
Defaults
A few Node.js packages are included by default in every CloudCode task. This includes:
aws-sdk
node-fetch
(exposed as a fetch global function)
Additional Node.js dependencies can be added to a task or managed via OXIDE. See the following section for details:
Manage External DependenciesPrivate NPM Packages
CloudCode supports the addition of private NPM packages to be used in tasks. To do this, you need to:
Update the task's
package.json
file with the relevant details for the private package you are using.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.Update the
yarn.lock
file (right-click on the CloudCode task in OXIDE or use the command palette).
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);
}
}
Last updated