DEV Community

Matsu
Matsu

Posted on

1

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!

AWS Security LIVE! Stream

Go beyond the firewall

There's more to security than code. Explore solutions, strategies, and the full story on AWS Security LIVE!

Learn More

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.

Jetbrains image

Is Your CI/CD Server a Prime Target for Attack?

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. It makes sense—CI/CD servers have access to source code, a highly valuable asset. Is yours secure? Check out nine practical tips to protect your CI/CD.

Learn more

👋 Kindness is contagious

Dive into this informative piece, backed by our vibrant DEV Community

Whether you’re a novice or a pro, your perspective enriches our collective insight.

A simple “thank you” can lift someone’s spirits—share your gratitude in the comments!

On DEV, the power of shared knowledge paves a smoother path and tightens our community ties. Found value here? A quick thanks to the author makes a big impact.

Okay