'How to Run Multiple Node.JS Version projects on the same machine on Ubuntu 18.04 with Nginx

Is it possible to have two or more different NodeJS versions and run at the same time?

Having 3 different versions on the same machine. For example:

Project 1: Run with 12 NodeJS version
Project 2: Run with 14 NodeJS version
Project 3: Run with 16 NodeJS version etc

I have a Linux 18.04 LTS server running with Nginx. Now I am using one version with pm2.

So far the closest solution to my problem is to use nvm. But nvm can install many versions but can use one version at a time.



Solution 1:[1]

You can use NVM for that. https://github.com/nvm-sh/nvm. Use nvm run or nvm exec

nvm run - executes node on a specific version, so: nvm run 10 npm start is equivalent to node npm start (with version 10 of node installed).

You can also use nvm exec - executing a command on a specific version:

$ nvm exec 10 npm -v
Running node v10.0.0 (npm v6.0.0)
6.0.0
$ nvm exec 6 npm -v
Running node v6.10.3 (npm v3.10.10)
3.10.10

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ev45ive