node.js – pm2 start app.js在15次重启后退出

前端之家收集整理的这篇文章主要介绍了node.js – pm2 start app.js在15次重启后退出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
npm start会启动我的应用程序就好了但是当我这样做时:
pm2 start app.js

我明白了:

[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Process app.js launched
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app      │ 0  │ fork │ 4681 │ online │ 0       │ 0s     │ 11.508 MB   │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
 Use `pm2 show <id|name>` to get more details about an app

在我得到的日志中:

[PM2] Starting streaming logs for [all] process
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:37: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:37: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:37: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:38: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:38: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:38: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Starting execution sequence in -fork mode- for app name:app id:0
PM2: 2015-06-04 17:12:39: App name:app id:0 online
PM2: 2015-06-04 17:12:39: App name:app id:0 exited with code 0
PM2: 2015-06-04 17:12:39: Script /home/user/app/app.js had too many unstable restarts (15). Stopped. "errored"

这是我的package.json:

1 {
  2   "name": "app",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 }

节点版本:v0.10.38
pm2版本:0.12.15

我怎么调试这个?我不确定为什么会失败,是否还有其他地方需要检查?我的app.js文件

解决方法

首先,我尝试使用node ./bin/www并确保其正常工作.

我不确定解决这个问题的“官方”方式是什么,但这应该有效:
您可以将未捕获的异常处理程序放入您的代码中,该代码只是写入文件或执行其他操作.

process.on('uncaughtException',function(err) {
    console.log('Caught exception: ' + err);
    throw err;
});

编辑:
根据您的评论,您遇到问题的原因是因为app.js不是您应用程序中的真正入口点.真正的切入点是./bin/www

所以你需要告诉PM2启动该文件而不是像这样的app.js:pm2开始./bin/www

原文链接:https://www.f2er.com/nodejs/241214.html

猜你在找的Node.js相关文章