Node.js dependencies

Install dependencies

To install dependencies, you can add them to your script's package.json via npm or yarn like you normally would:

bash
Copied
1
# Example installing the airplane SDK
2
# Updates package-lock.json
3
npm install airplane

You should place your package.json file either next to your task or in a parent directory. The closest directory containing a package.json becomes the task root—the task root is uploaded when deploying.

Airplane skips installation of devDependencies—if your application requires devDependencies, you can override the install command. See Custom build steps.

Private npm packages

To install private packages from NPM, you'll need to generate an access token with read-only permissions. Add it as a Config Var and set it as an environment variable called BUILD_NPM_TOKEN:

Environment variables are set at build time in addition to runtime—when building, Airplane will look for BUILD_NPM_TOKEN and configure a .npmrc file for you.

Other private packages

If you're using other private registries like GitHub packages, you can upload the entire contents of your .npmrc file as a config variable (assuming the tokens are stored there) and set the BUILD_NPM_RC environment variable:

Upload .npmrc as a config variable.

Copied
1
// .npmrc
2
//registry.npmjs.org/:_authToken=TOKEN_FOR_NPM
3
//npm.pkg.github.com/:_authToken=TOKEN_FOR_GITHUB
bash
Copied
1
cat .npmrc | airplane configs set --secret npmrc

Set the BUILD_NPM_RC environment variable.

yaml
Copied
1
node:
2
envVars:
3
BUILD_NPM_RC:
4
config: npmrc

npm/Yarn workspaces

By default, the airplane CLI will find the nearest package.json and use that as the root of your task. All code in the root is included when building the task.

If you're using npm or Yarn workspaces, you may want the root to be the parent directory, so that you can install sibling packages. For example, you might be deploying packageA/scripts/myScript.ts:

Copied
1
/
2
package.json
3
packageA/
4
package.json
5
scripts/
6
myScript.ts
7
packageB/
8
package.json

While packageA/package.json will be identified as the root package.json for your task, you'll also want to include the parent folder (and siblings like packageB/) in the build.

To do this, in packageA/package.json you can override the root to be a parent directory:

javascript
Copied
1
// packageA/package.json
2
{
3
"airplane": {
4
"root": ".."
5
}
6
}

This will cause the root to get moved up a level, thus including packageA/ as well as packageB/ in the build. Note that the working directory will remain at packageA/—any build/install commands will still be run from the subdirectory.