Managing your Node.js installation

Ever get weird errors about unsupported features when running your React app's dev server? Chances are your codebase is written for a specific version of Node, and you don't have it installed.

Or perhaps you know which version of Node each project uses, and you manually install a specific version of Node before getting started.

There's a few tools we can use to manage this for us!

nvm - node version manager

Node version manager is one of the more popular ways to manage your local Node version when developing.

You install a new version of Node by running nvm install 18 in your Terminal, and swap Node versions by running nvm use 18 (or whichever version of Node you want to use).

You can also lock the version of Node your project uses by including an .nvmrc file in your project's root, containing the version of Node you want everyone to use.

The downside to using nvm is that you tend to forget which version of Node you're using, as it doesn't automatically change versions between projects. The fix is to setup up a script in your Terminal to automatically search for an .nvmrc file and change Node versions when you change directory, but other tools do this automatically, like volta.

Volta

Volta does things a little differently. Firstly, it's written in Rust, so changing versions should be very fast, and secondly, it's designed to get out of your way - so you don't even need to manually change Node versions when switching projects.

To do this, you need to run volta pin node@18 in each of your projects, and it'll update your package.json file to add config that volta uses to automatically switch versions.

I personally use this at work and it feels like magic. The only annoying thing I've noticed is how Volta handles global installs. You can run npm install -g wrangler for example, but if you want to update it afterwards, confusingly, you have to run volta install wrangler.

pnpm

You might know pnpm as a ridiculously fast package manager that supports monorepos, but it also manages your node version.

asdf

If you use more than one runtime, you might be interested in asdf as an all-in-one tool for managing your node, java, ruby (and more) runtime versions.

asdf also supports automatically updating Node versions via .nvmrc and .node-version files - described in asdf-nodejs.

Want more articles like this?

I send a single email every two weeks with an article like this one, to help you be a better React developer.

Lots of developers like them, and I'd love to hear what you think as well. You can always unsubscribe.

    Join 947 React developers that have signed up so far.
    See my privacy policy.