How to run multiple versions of NodeJS with nvm for Windows

Stavros Kounis
Appseed IO
Published in
4 min readOct 30, 2015

--

Introduction

Node.js is the key for many Javascript applications. As Node.js is still a go-to solution, many versions of it are released and new versions will be released in the future. That is where testing an application with various Node.js version comes handy. Below, you will find all you need to know in order to run an application with a particular Node.js version using nvm for Windows.

Prerequisites

In this tutorial, we will use Windows command line tool, therefore, a little familiarity with command line would be useful.

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. Just follow the prompts of the Setup Wizard.

After the end of the installation of this version there is a chance the CLI will crash with the following error:

To overcome this error, follow these steps:

  1. Go to c:\Users\{username}\AppData\Roaming\nvm directory,
  2. copy settings.txt and
  3. paste it to c:\ .

Now, run the setup file again and you should get something similar to this:

Step 2: Install Node.js

If you have not already installed Node.js on your machine, it is time to install the latest or a specific version of Node.js using the utility we installed in the previous step. We will install version 0.12.7 for 64-bit Windows by running the command:

$ nvm install 0.12.7 64

When the installation is completed successfully, you will see the following:

Similarly, 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

Also, do not forget to start a new command line session so the added Node.js to the PATH variable will take effect. So, close the command line and open it again.

Step 3: List the available Node.js versions

In order to list all the Node.js versions installed on your machine, simply run the command:

$ nvm list

If you installed the versions we mentioned earlier, this command returns the following versions:

Step 4: Use a specific Node.js version

Firstly, let’s create a very simple program which will print out the current Node version we are using. Open your favorite text editor and put the following line of code:

console.log(‘Node version in use: ‘ + process.version);

Save the file as testingnode.js. Now, we will run our script using Node.

But, before we run it, we can define the Node.js version we want to use. We will use version 4.2.1 by running the command:

$ nvm use 4.2.1 64

Now, navigate to the folder where you saved the testingnode.js file and run our program with the following command:

$ node testingnode.js

Conclusion

In this tutorial, we used nvm for Windows in order to manage and run specific Node.js versions. However, you can use other alternatives, such as nvmw and nodist.

Interesting in Ionic?

Check out our Ionic and Ionic 2 Starter Kits and Application Templates.

Enjoyed this Post?

Follow us on Twitter, or Google+ or even check our CodeCanyon Profile. You may also take a look at our website www.appseed.io

References

Node.js, nvm for Windows, Dmitry Baranovskiy for the cover photo.

Happy coding,
The AppSeed team

/Stavros Kounis, skounis.github.io

--

--

Stavros Kounis
Appseed IO

Software developer and Javascript enthusiast, passioned with web and mobile technologies, skounis.github.io