简体   繁体   中英

How to create pm2 ecosystem.json file for node js express app which starts using npm start?

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.

  1. It is not configured in ecosystem.json file.
  2. It is not obeying the -i 0 parameter. It only start single instance.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM