How to run multiple app using PM2?
Asked Answered
C

3

7

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.

Circumfluous answered 21/12, 2017 at 7:17 Comment(4)
The question is misleading and conceals real problem. The purpose of PM2 is to run the app 'forever', regardless of whether terminal window is open or not.Siddra
@estus the other one is working properly but the second one is running stop when i close the Terminal, Do you have any proper solution? should i run this command as a ROOT?Circumfluous
@Chaudhary You still having problem??Les
@Vishantdhandha still having same problem.Circumfluous
V
14

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

Violaviolable answered 21/12, 2017 at 7:36 Comment(0)
T
5

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

You can check that server is online or not.

Trost answered 21/12, 2017 at 7:26 Comment(3)
still having same issue, it will work but when i close the Terminal it will Stop.Circumfluous
Did you check the status?Trost
@Yoesh Patel when i run this Command from ROOT it will works fine, thanxxCircumfluous
E
2

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

Eastsoutheast answered 16/4, 2019 at 19:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.