titletext | description |
---|---|
How to use specific Node.js versions, and private packages |
Your project may require a specific version of Node.js. Or, you may need to use private npm packages. This section shows you how to do both.
|
Node.js, or just Node, is a popular JavaScript runtime that can be used for application development or system tools.
This section covers the following topics:
Node itself is evolving rapidly, which means that new features are available regularly. It also means that existing features might change or become deprecated. Your use of Node may depend on specific versions in order to function correctly. See how to use a specific version of Node in the following steps:
-
Log in to the buddybuild dashboard.
-
Choose the app that requires a specific Node version by moving your pointer over the current app button in the top toolbar. The Apps dropdown appears:
-
Select the app that needs a specific Node version by clicking it in the dropdown. The Builds page for your app appears:
If you have many apps, you can type the app’s name (or portion thereof) into the search field; only apps with matching names are displayed.
Or, you can click the sort order button to display a select menu of sorting approaches. Click the select menu to display all of the approaches:
-
Alphabetical (A-Z) Select to show apps in normal, alphabetical order. This is the default.
-
Alphabetical (Z-A) Select to show apps in reverse alphabetical order.
-
Created Date Select to show the most recently added apps first.
-
-
Click the App Settings button in the top toolbar. The App Settings screen is displayed:
-
Click the Environment tab. The Environment settings are displayed:
-
Click the Node version select menu to display the available Node versions.
-
Click the version of Node that you need for your build.
That’s it! From now on, builds of your app use the selected Node version.
You can configure buddybuild to use private npm packages. This makes it much easier to mix public packages with custom, private code you have written. For more information on private packages, see Working with private modules.
Using private npm packages requires an account on npmjs.com. If you do not already have an account, sign up for a free account.
Once you have an npmjs.com account, you can then acquire the
access_token
which gives you access to all npm packages to which you
have at least read
permissions. Then you can set a buddybuild
environment variable to make the access token available to your build.
Finally, you can create (or update) the buddybuild_postclone.sh
script
to configure npm to use your access token and install your private
package dependencies.
Follow these steps:
-
Capture the npm access token:
-
From the command line, log in to npm:
npm login
You are prompted for your npmjs.com username, password, and email address.
-
Copy the access token from
~/.npmrc
.cat ~/.npmrc //registry.npmjs.org/:_authToken=cb31c41d-3bq8-7285-fe20-361ea25e3c1e
The access token is the value after
_authToken=
, in this case:cb31c41d-3bq8-7285-fe20-361ea25e3c1e
.
-
-
Set a buddybuild environment variable, to provide the npm access token to your build:
-
Log in to the buddybuild dashboard.
-
Click App Settings button in the top toolbar. The Default build configuration screen is displayed:
-
Click the Environment tab. The Environment settings screen is displayed:
-
In the Environment variables row, click the Configure button. The Environment variables screen is displayed:
-
In the Name field, enter
NPM_AUTH_TOKEN
. -
In the Value field, enter the npm access token that you copied previously.
-
-
Configure the build to use the environment variable:
-
Create (or update) the
buddybuild_postclone.sh
script in the root of your app’s repository, so that it contains the following lines:#!/usr/bin/env bash npm config set //registry.npmjs.org/:_authToken $NPM_AUTH_TOKEN npm install
-
Commit the change to
buddybuild_postclone.sh
.
-
That’s it! Your builds now have access to your npm access token, and
your app’s npm dependencies are installed, including any private
packages where you have read
permissions.