Justin Lok
Justin Lok

Reputation: 1270

PM2 not starting node.js app in multiple instances

Both of these each work to start my app:

node app
pm2 start app.js

The following does not work (app not working but PM2 status shows 2 instances online) and does not log any errors:

pm2 start app.js -i 2 --watch -l log/log.log

Launching with the following process.json file also does not work (but PM2 status still shows 2 instances online) and does not log any errors:

{
  "apps" : [{
    "name"        : "app",
    "script"      : "./app.js",
    "instances"   : 0,
    "exec_mode"   : "cluster",
    "watch"       : true,
    "ignore_watch"  : ["tmp","public","images_review"],
"error_file"      : "./logs/error.log",
"out_file"        : "./logs/out.log",
    "log_date_format"  : "YYYY-MM-DD HH:mm Z",
  }]
}

Launching in fork mode with the following process.json file still does not work but does log an error.

{
  "apps" : [{
    "name"        : "app",
    "script"      : "./app.js",
    "instances"   : 0,
    "watch"       : true,
    "ignore_watch"  : ["tmp","public","images_review"],
"error_file"      : "./logs/error.log",
"out_file"        : "./logs/out.log",
    "log_date_format"  : "YYYY-MM-DD HH:mm Z",
  }]
}

The error it logs is "Error: listen EADDRINUSE :::3000". I checked and nothing is using port 3000. I also switched my node.js app to use a different port and it still gives an EADDRINUSE error for every port I try. I'm on a 2 core linode with Centos 7 running Plesk Onyx. What's going on that I'm missing?

Upvotes: 4

Views: 10391

Answers (4)

Alexandre
Alexandre

Reputation: 1

I solved the problem by switching from node 22 to node 23

Upvotes: 0

Vishesh Verma
Vishesh Verma

Reputation: 1

Try deleting the default process using "pm2 delete all" Worked for me!!

the default process that needs to be deleted:

Upvotes: 0

Prerna Jain
Prerna Jain

Reputation: 1240

Got it solved with PM2 version somehow.

Issue : With version 3.0.3, it did not work in cluster mode.
However, when downgraded PM2 version to 3.0.0, it worked.

Agree with @robertklep's comment though.

Upvotes: 0

kennasoft
kennasoft

Reputation: 1593

Can you try running it with

pm2 start app.js -i 0 -l log/log.log

Which makes pm2 use the maximum number of cores available

Then you can view your logs in real time using

pm2 logs

Upvotes: 3

Related Questions