How to run multiple app using PM2?

≡放荡痞女 提交于 2019-12-24 11:59:28

问题


I want to run my angular4 app using PM2 it will run but when I am close the terminal it will stop.

  1. On this server already run one application, it is working properly, but in my app it will work when I am open the terminal, otherwise it will stop

    pm2 start server.js

I am using this command to run my app but when I am Close the Terminal immediately it will stop, so how can I run this app Forever using PM2.


回答1:


If you are using PM2 properly, your applications should not be turning off after terminal exit. It is very likely that your application is failing. Run pm2 logs to diagnose.

You can specify multiple applications in a process.json file like this:

{
    "apps" : [{
        "name"        : "worker",
        "script"      : "./worker.js",
        "watch"       : true,
        "env": {
            "NODE_ENV": "development"
        },
        "env_production" : {
            "NODE_ENV": "production"
        }
    },{
        "name"       : "api-app",
        "script"     : "./api.js",
        "instances"  : 4,
        "exec_mode"  : "cluster"
    }]
}

Documentation Here

Started like this:

pm2 start process.json

And can monitor/view your applications by running pm2 monit or pm2 ls




回答2:


You can start any NodeJs server using pm2 start ****.js --name "Project Name".

You can check that server is online or not.




回答3:


Everything is fine just run below command from ROOT

1) first go to your Project Directory and run below from from ROOT.

pm2 start server.js

it will work fine.




回答4:


If you are running the same script multiple times, with different parameters for instance, just give them different names.

i.e.

PM2 Start Engage.js --name Warp1

PM2 Start Engage.js --name Warp2

PM2 Start Engage.js --name Impulse



来源:https://stackoverflow.com/questions/47919811/how-to-run-multiple-app-using-pm2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!