To run several versions at the same time. In pm2, you can use the --interpreter options and specify the path to the node version you want.
You may install different node versions using nvm.
Install NodeJS using Version Manager
Running direct script using PM2 process file:
module.exports = {
apps : [{
name : "app1",
cwd : "/home/user/app1", // folder store the application
script : "./app.js", // starting js file
interpreter : 'node@6.9.1' // Node version
},
{
name : "app2",
cwd : "/home/user/app2",
script : "./app.js",
interpreter : 'node@12.9.1'
}]
}
Running using npm script using PM2 process file:
module.exports = {
apps : [{
name : "app1",
cwd : "/home/user/app1", // folder store the application
script : "/home/user/.nvm/versions/node/v6.9.1/bin/npm", // Folder where the npm stored
args : ["run", "start"], // Argument pass to npm
interpreter : 'node@6.9.1' // Node version
},
{
name : "app2",
cwd : "/home/user/app2",
script : "/home/user/.nvm/versions/node/v12.9.1/bin/npm",
args : ["run", "start"],
interpreter : 'node@12.9.1'
}]
}