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:
lts/hydrogen
Then, you can configure the Github Action so to use the same .nvmrc file.
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node env
uses: actions/setup-node@v3
with:
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.
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Related Posts
Migrate URLs in Next.js
How to migrate URLs in Next.js to avoid 404 errors and improve SEO with permanent redirects.
Collapsible sections in Markdown
Collapsible sections can help keep markdown organized and user-friendly. In this quick guide, we'll show how to create collapsible sections in a markdown.
Inject HTML content into an Astro component
While working on a project within the Astro framework, I encountered a scenario where I needed to fill HTML content within a script tag.
Featured Posts
Introducing new blog about OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.