Versions
This best practice details which Node.js, npm and yarn versions should be used.
Description
Each repository should have a single version of Node.js, npm and/or yarn that is clearly documented in the repository.
The easiest way to do this is to use node version manager / nvm and have a .nvmrc
file in the root of the repository. nvm allows the ability for engineers to quickly install and use different Node.js and npm versions. Documentation should also be added to the README.md file so it is clear how to setup the correct version of Node.js, npm and/or yarn.
Node.js Version
For versioning of Node.js the latest LTS version should be used. This can be found on the Node.js website.
There will be some exceptions to this but we encourage the use of the latest LTS version to ensure long term support.
npm Version
For versioning the latest associated npm version to the Node.js version should be used. When using nvm this is done automatically.
This table shows the latest npm version for each Node.js version.
Other Package Managers
For other package managers such as yarn it is recommended using the latest stable and supported version. Documenting the version in the README.md file is still recommended.
Rationale
To improve the developer experience and to avoid conflicts between developers the repository should use a single version of Node.js, npm and/or yarn. Using different versions of Node.js, npm and/or yarn can lead to unexpected behaviour and errors. For example using different npm versions can lead to different lock files being generated erroneously.
By making it clear what version of Node.js, npm and/or yarn in the repository it clarifies to engineers what version they should be using to have a consistent experience.
Examples
In the root of the repo have a file called .nvmrc
with the following contents:
v18.14.2
You can generate it via: node -v > .nvmrc