Reputation: 1446
I want to use pm2 for node js express app. I am able to start node js server using npm start. I want to configure the same in ecosystem.json file so that i can start by using pm2 tool. Also i want to start in cluster mode.
Please note that i am able to start the node js app by using the command below
pm2 start "/usr/bin/npm" --name "blaze-node" -- start -i 0
There are two problems with the above command.
Some more information
Below is the ecosystem.json file
{
"apps":[
{
"name":"blaze-node",
"script":"npm",
"exec_mode":"cluster",
"instances":"0",
"env_dev":{
"watch":true,
"NODE_ENV":"dev"
},
"env_qa":{
"watch":false,
"NODE_ENV":"qa"
},
"env_prod":{
"watch":false,
"NODE_ENV":"prod"
}
}
]
}
If i execute the below command pm2 start ecosystem.json --env dev it show the nice output showing that the processes have been started. But nothing is getting listened on 3000 port.
Instead when i use the command without using ecosystem.json file as below
pm2 start "/usr/bin/npm" --name "blaze-node" -- start -i 0
Every thing works fine except those two problems as stated above.
Please help.
Upvotes: 4
Views: 2830
Reputation: 3084
You can probably use a combination of script
, args
, and node_args
within a pm2 config.js to achieve this. It sounds counter-intuitive to have pm2 script entry point call an npm script entry point to invoke a script! Better to bypass package.json at this point and achieve the same script execution using those 3 config parameters in combination.
Upvotes: 0