Ever work on different projects that depend on different versions of Node? I recently ran into an issue where I had one project that depended on Node 10, and another (this website actually) depend on Node 12. Put me in an interesting situation. I wasn’t about to go and uninstall/reinstall versions of Node every time I switched projects. So I did a little digging and discovered a project called Nodist.
Nodist allows you to quickly swap out the active version of Node on your box. Here are some of the commands I personally use. To get started, head over to the releases page of the Nodist project here and install the latest version.
Setting your Active Node Version
In Nodist, there is the concept of the global version & the local version. The global version is the node version that’s used by default. I set mine to the latest (12 at the time of this writing) by issuing the following command in my terminal;
nodist global 12
One of the neat things about Nodist is you don’t need to install a version manually. When you set the version, Nodist will automatically download and install the latest dot release of Node for that major release. You can also set the entire version if you want;
If you’re working on a project that requires a different version, you can set it on the directory level using;
nodist local 10
Now whenever you issue Node & NPM commands in that directory, it will use the version specified instead of the global version.
Setting the NPM Version
If you want to use different NPM versions, you can also use Nodist to set that as needed;
nodist npm global 12 nodist npm local 10
You can also set NPM to whatever version matches the version of Node you have set;
nodist npm global match
Using Nodist makes swapping out versions of Node & NPM much easier than trying to tackle it manually. Head over to the repo to view the full documentation here.