Motivation
I was recently working on a project that ran a different version of Node and had forgotten to switch Node verisons using nvm. Normally this isn’t an issue except that I didn’t have an .nvmrc file in this particular project to help me make the switch and ran into some odd compatibility problems that I eventually traced to this forgotten step. It was here that I figured, I’ve used NVM for years now - is there anything out there worthwhile checking out?
I stumbled on Volta from flipping through various different search results including a small blurb from a 2022 edition Thoughtworks Tech Radar and what drew me to try it was:
- Promise of a simple install
- Easy switching between versions when switching from one project to the other without having to use .nvmrc.
- Managing tools such as pnpm, npm, yarn, etc. that are pinned to a specific version of Node based on whatever the project requires.
- NVM had served me well for years but the promise of automatic handling of Node version and the associated tools between projects is too good not to try it out.
Installing Version Specific Tooling
It has been great to know that I can simply install any tooling that I can use with a specific version of Node. For example, I use Astro and PNPM I and decided to install the tools (which at time of writing is Node 22.14.0) against that specific version which I can use globally.
$ volta list
⚡️ Currently active tools:
Node: v22.14.0 (default)
npm: v11.2.0 (default)
Tool binaries available:
astro (default)
pnpm, pnpx (default)
Volta automatically adjusts to use the version that’s required in a project.
$ volta list
⚡️ Currently active tools:
Node: v22.14.0 (current @ /cblanco-dev/package.json)
npm: v11.2.0 (default)
Tool binaries available:
astro (current @ /cblanco-dev/package.json)
pnpm, pnpx (default)
Setting Node Version to Project
Volta uses the package-lock.json file to specify versions and tooling. I think this is nice as it’s one less file to have to worry about. Defining the version is simple via the pin command.
$ volta pin node@lts
success: pinned [email protected] (with [email protected]) in package.json
Migration Steps Taken
Removing NVM
Before installing Volta I removed NVM using NVM’s uninstall instructions Make sure you restart your terminal sessions before continuing to ensure there’s no lingering trace of nvm. At this point you should not have Node on your system.
Install Volta
Installation was fairly straighforward using Volta’s guide Just to make sure you’re using Node served via Volta
$ which node
/Users/carlos/.volta/bin/node