DEV Community

Matsu
Matsu

Posted on

Setting a Default Node Version for Your Project with .nvmrc

I used to switch between projects and wonder why some things just... broke.

Then I realized the issue: each project was using a different Node.js version.

Sometimes one needed Node 18 for a modern API, while another was still running on 16.

That’s when I found out about .nvmrc.


What is .nvmrc?

It’s a simple file that you add to the root of your project to define the Node.js version that should be used.

No JSON. No config object. Just the version number.

18.16.1
Enter fullscreen mode Exit fullscreen mode

How does it work?

When using NVM (Node Version Manager), you can run:

nvm use
Enter fullscreen mode Exit fullscreen mode

And NVM will automatically switch your Node.js version to the one specified in .nvmrc.

This is super helpful when you clone a repo and want to make sure you're using the right environment.


Why it matters

  • Keeps your local version consistent with the project
  • Prevents bugs caused by incompatible Node versions
  • Makes onboarding easier for teams

If you're working with multiple Node projects, this tiny file can save you hours of debugging.

Console You Later!

Top comments (1)

Collapse
 
bywaleed profile image
Waleed

👏 Nice post. There is also .node-version file which is used by multiple node version managers. Here is a list of it's compatibility.