Skip to main content
Each Upsun container image includes a specific language in a specific version. A set of dependencies is also provided based on that language version. This ensures that your application container is as small and efficient as possible. Therefore, by default, when you use an Upsun container image, you use the Node.js version that’s included in that image, if any. If you want to use a different Node.js version, use a version manager to install it yourself. You can use one of the following version managers: Both of the recommendations use a .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.
  1. Add the desired Node.js version to your environment using .nvmrc, .n-node-version, .node-version, or package.json.
Create a .nvmrc file in your app root:
.nvmrc
v16.13.2
  1. Add it as a dependency:
Adding it as a dependency ensures it’s cached for future builds.
  1. Set the location of the n files using the N_PREFIX environment variable:
  1. Install the specified version of Node.js in a build hook:
Now your hooks should be able to use the specified version of Node.js. You can verify this by running 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.
To use nvm, follow these steps:
  1. Define which nvm version to use using an environment variable. Add it to your app configuration:
  1. Define your desired Node.js version using an environment variable. For your base version, set it in your app configuration:
To get different versions in different environments, set environment-specific variables.
  1. Add a .nvm directory 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:
rsync -av $PLATFORM_CACHE_DIR/.nvm $PLATFORM_APP_DIR
  1. Use the cache directory and install based on the variables if not present:
  1. Optional: To use the specified Node.js version in the runtime container and not just the build, activate nvm via script:
    .environment
    unset NPM_CONFIG_PREFIX
    export NVM_DIR="$PLATFORM_APP_DIR/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    
    Your final app configuration should look something like the following:
Last modified on March 11, 2026