Keep the same Node.js version between local environment and Github Actions

Emmanuel Gautier / October 30, 2022

2 min read

It can be complicated to have the same Node version between the local environment and the CI/CD. The latest Node.js version or the latest lts is released recently and if you want to upgrade to the Node version, usually you can forget to configure one environment. For that reason, it can be important to have only one source of truth to define the Node version, so you change in one place it impacts every environment.

Here we will use nvm and have the CI/CD example with Github Actions. Some other CI/CD solutions can exist elsewhere using a similar configuration and reproduce the common configuration.

First of all, you should configure a .nvmrc file defining the version you want to use. This version will be used in your local environment. To use it, you can either make an nvm use each time you go to the project's local directory or configure your bash to use it automatically.

Here is an example of a .nvmrc file content:


Then, you can configure the Github Action so to use the same .nvmrc file.

      - name: Checkout
        uses: actions/[email protected]

      - name: Setup node env
        uses: actions/[email protected]
          node-version-file: '.nvmrc'
          cache: 'yarn'

Now, when you change the .nvmrc file, it changes the version used for your local environment, the Node environment for all your team, and the CI/CD running on Github.

Share this post
Follow the RSS feed

Subscribe to the newsletter

Get emails from me about web development and a lot of topics related to tech.