.nvmrc file to specify the desired Node.js version.
You could also specify a different file or use environment variables.
Use n
The n package works for various Unix-like systems,
including Windows Subsystem for Linux.
- Add the desired Node.js version to your environment using
.nvmrc,.n-node-version,.node-version, orpackage.json.
- .nvmrc
- .n-node-version/.node-version
- package.json
Create a
.nvmrc file in your app root:.nvmrc
- Add it as a dependency:
- Set the location of the
nfiles using theN_PREFIXenvironment variable:
- Install the specified version of Node.js in a
buildhook:
node -v.
Your final app configuration should look something like this:
Use nvm
Node Version Manager (nvm) is a bash script for managing Node.js versions.
You can use it to:
- Make a specific version available in the build and optionally the runtime container.
- Control the specific versions to be installed with environment variables, meaning you can also have different versions in different environments.
nvm, follow these steps:
- Define which
nvmversion to use using an environment variable. Add it to your app configuration:
- Define your desired Node.js version using an environment variable. For your base version, set it in your app configuration:
- Add a
.nvmdirectory to your cache in your build hook:
Instead of using a symlink between your cache and application directories,
you might need to copy the content of
$PLATFORM_CACHE_DIR/.nvm into $PLATFORM_APP_DIR/.nvm manually.
To do so, run the following command:- Use the cache directory and install based on the variables if not present:
-
Optional: To use the specified Node.js version in the runtime container and not just the build,
activate
nvmvia script:Your final app configuration should look something like the following:.environment