pm2 crashes with too many unstable restarts

Created on 4 Jun 2015  路  7Comments  路  Source: Unitech/pm2

I do:

pm2 start app.js

The app doesn't start and I get this repeated in the logs:

PM2: 2015-06-04 13:21:10: App name:app id:1 exited with code 0
PM2: 2015-06-04 13:21:10: Starting execution sequence in -fork mode- for app name:app id:1
PM2: 2015-06-04 13:21:10: App name:app id:1 online
PM2: 2015-06-04 13:21:11: App name:app id:1 exited with code 0
PM2: 2015-06-04 13:21:12: Script /Users/conwilly88/Desktop/myapp/app.js had too many unstable restarts (15). Stopped. "errored"

here's my package.json:
1 {
2 "name": "myapp",
3 "version": "0.0.0",
4 "private": true,
5 "scripts": {
6 "start": "node ./bin/www"
7 },
8 "dependencies": {
9 "body-parser": "~1.12.4",
10 "cookie-parser": "~1.3.5",
11 "debug": "~2.2.0",
12 "express": "~4.12.4",
13 "jade": "~1.9.2",
14 "morgan": "~1.5.3",
15 "serve-favicon": "~2.2.1",
16 "stylus": "0.42.3"
17 }
18 }

Does anyone know how I can debug this or why it's not launching? Any help is appreciated.

Side note:

node app.js doesn't do anything but npm start will launch my app (referencing http://stackoverflow.com/questions/22215592/default-node-js-express-js-does-not-run)

Most helpful comment

for anyone else wondering I had to use:

pm2 start ./bin/www

works just fine now

All 7 comments

for anyone else wondering I had to use:

pm2 start ./bin/www

works just fine now

Why is this "pm2 start ./bin/www" working? The instruction is to use pm2 start "your js" file not ./bin/www
anyone know the answer?

So, if you are using express add this to your app.js (or just entry point) then pm2 start app.js will work fine. example:
app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
debug('Express server listening on port ' + server.address().port);
});

pm2 update

try upgrading node version

Same error in empty default nodejs express app (v.4.16.00, express-generator).
Solved by using pm2 start bin/www instead of pm2 start app.js - different starting point.

It can be solved also by creating pm2.process.json in root folder, for example:
{
"script": "bin/www",
"watch": true,
"ignore_watch": ["FOLDER_NAME_TO_IGNORE"],
"watch_options": {
"followSymlinks": false
},
"name": "APP_SERVICE_NAME"
}

And then use pm2 start pm2.process.json

I had a different issue, causing the same symptom. Here's what was wrong:
My dev environment was configured like:

"env": {
      "NODE_ENV": "development",
      "node_args": ["--debug=9229"]
}

Note the --debug That WAS causing a warning (that it is deprecated and must be --inspect) but I ignored it because 1. it was a warning and 2. I figured there would be something in the version notes of PM2 - nope. It turned out, that WAS the cause of the immediate crashes. I changed debug to inspect and now PM2 will start Node.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

psparago picture psparago  路  3Comments

rajendar38 picture rajendar38  路  3Comments

ghost picture ghost  路  3Comments

chaos-git picture chaos-git  路  3Comments

shaunwarman picture shaunwarman  路  3Comments