use pnpm as a Node.js version manager

pnpm ships with a streamlined, easy way of managing Node.js versions for youself and your team. This video demonstrates why pnpm uses a specific version of Node.js, how to configure it globally, and how to set up your project so that anyone who is running your project will automatically use the same version of Node.js even if that version of Node.js is not installed.

Share with a coworker

Social Share Links

Send Tweet

Transcript

[00:00] When running a script with pnpm, which will fire off this script, and this will log out the node version, this is using the pnpm and use global and I'll set ours to 20.18. So this time when I run this script you'll see it now executed with 20.18. But what you can do in your project is create a .npmrc file and you can say use node version and I'm going to set this to 23.0.0. And now when I run that same script pnpm start this will automatically pick up from our project that we want node 23 and run the script with node version 23. Now I already have version 23 installed, but the cool thing here is if I remove the version 23.0.0 you'll see it removed it from my pmpm directory.

[00:45] If I attempt to run the script again, pmpm start, you'll see it'll now trigger a download of that version of Node and then run the script. Making this an awesome solution for defining the specific version of Node you want to use across your projects. Nobody has to worry about installing Node or even which version of Node to use. Any script that is run by PNPM will just automatically use the version defined in NPMRC.