Nodejs app

Run multiple Node.js apps with different Node.js version in Same server

Due to dependency issues and upgrade in Node.js versions, some applications still requires old Node.js versions.

In the scenario, where you need to run two or more applications which require a different version of Node.js you either need to upgrade or downgrade the Node.js version in the system and that sometimes becomes the root of many issues.

Node version manager

No more of this. You can install multiple version of Node.js in a single machine and can run different programs with a different version of Node.js.

Introducing Node version manager by Creationix. This script manages multiple active Node.js version to install and run Node.js program with different Node.js version.

Installing NVM

To install NVM, you need CURL or WGET program installed in your machine.

I have installed using CURL. Here is the command.

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

You can install using WGET too.

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

Once installation is done, export the NVM as command line tool using following command.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

Installing Node.js using NVM

If you want to install latest version of Node.js then run following command.

nvm install node

If you want to install a specific version, run the following command.

nvm install 4.2.5

Or

nvm install 6.0.0

Install as many as you would need.

Running Node.js program using NVM

Say you want to run one program using Node.js version 4.2.5. Run it using following command.

nvm run 4.2.5 app.js

Replace version number with any installed version and NVM will execute it for you.

You can also set the Node.js version for the terminal session (Each tab on the terminal is different terminal session) using the following command.

nvm use <node version>

Then run the app using standard Node.js command.

node <app file>

Conclusion

This is short tip post and I hope it helps you to solve such issue where you need to run multiple Node.js application with different Node.js version.

Shahid (UnixRoot) Shaikh

Hey there, This is Shahid, an Engineer and Blogger from Bombay. I am also an Author and i wrote a programming book on Sails.js, MVC framework for Node.js.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *