Reputation: 636
How to run 2 or more node app with pm2? I tried with different ways by referring (https://stackoverflow.com/a/39316957/11983640) and other links also but its not happening. Any solutions?
Upvotes: 0
Views: 1206
Reputation: 187
I suppose you want to run with pm2 different apps . For that case generate an ecosystem file with :
pm2 ecosystem
And then set your scripts to run as you want . An example :
ecosystem.config.js
module.exports = {
apps : [{
name: 'MyNodeApp',
script: 'bin/www',
args: '',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
},{
name: 'back-up',
script: './backup',
args: '',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}],
};
Run your pm2 with :
pm2 start ecosystem.config.js
With the above eco file i start 2 different apps with pm2 the first is my main app (name:MyNodeApp) and the second is a back up script .
Upvotes: 1
Reputation: 1269
If you want to host multiple node projects on pm2, you can just do it like this
pm2 start path/to/first/node/project/main_file.js --name "project_1"
pm2 start path/to/another/node/project/main_file.js --name "project_2"
Just make sure both projects are running on different port
Upvotes: 0