When you are a NodeJS developer and you run multiple applications, you might encounter some on-spot situations. For example, maybe you have the latest version of Node set up on your machine, yet the project you’re about to start working on requires an older version or vice versa. Without a good tool, such as NVM, you will have to spend a lot of time and effort in order to get it live.
Before coming to explore how to use NVM, first, let’s go to the definition.
What is NVM (Node Version Manager)?
This stands for Node Version Manager. As the name suggests, it helps you manage and switch between different Node versions with ease. It provides a command-line interface where you can install different versions with a single command, set a default, switch between them, and much more. NVM works on any POSIX-compliant shell (sh, dash, ksh, zsh, bash), in particular on these platforms: UNIX, macOS, and windows WSL.
Above, we may understand a little bit about this term. So, let’s take a further step to the usage. Moreover, in this tutorial, we will use Windows command-line tool, therefore, a little familiarity with the command line would be useful.
The following let’s go to find out how to use NVM.
How to use NVM to run multiple versions of Note.js?
Step #1: Install NVM for Windows
Firstly, we need to install NVM for Windows – which is the tool that will enable us to switch between different versions of Node.js. We will install the latest release of this tool (v1.1.0). The installation is pretty easy because you can just follow the prompts of the Setup Wizard. Then, all you have to do is running to the setup file
Step #2: Install Node.js
If you have not already installed Node.js on your machine, then it’s quite urgent. So, you should install the latest or a specific version of Node.js. We will install version 0.12.7 of NVM for 64-bit Windows by running the command:
$ nvm install 0.12.7 64
A note to yourself: do not forget to start a new command-line session so the added Node.js to the path variable will take effect. To do this, you may have to close the command line and open it again. Moreover, you can install as many Node.js versions as you want. We will go ahead and add version 4.2.1 with the command:
$ nvm install 4.2.1 64
And you’re set to dig down.
Step #3: List the available Node.js versions for NVM
In order to list all the Node.js versions installed on your machine, simply run the command:
$ nvm list
And as a result, your screen will return the result like this:
Step #4: Use a specific Node.js version
So, let’s create a very simple program that will print out the current Node.js version we are using. Open your favorite text editor and put the following line of code:
console.log(‘Node version in use: ‘ + process.version);
Then, save the file as testingnode.js. Now, we will run our script using Node. However, before we run it, we can define the Node.js version we want to use. We will use version 4.2.1. After that, you should navigate to the folder where you saved the testingnode.js file and run our program with the following command:
$ node testingnode.js
And your NVM usage is settled!
That should conclude the steps on how to use NVM (Node Version Manager) to run multiple versions of Node.js effortlessly. All in all, Node Version Manager is a great tool for any Node.js developer. It enables a concern-free installation and easy switching between different versions, saving time for what really matters. As a result, your software development using Node.js will be much more effortless and focused. Finally, are you clear about how to use NVM? If not, let’s us know at CONTACT FORM