[英]Nodejs + expressjs - pm2 and forever don't work?
我想让一个应用程序在我的nodejs服务器上永远运行。 但是它似乎不适用于pm2和永远 。
如果我手动启动该应用程序:
$ npm start
> iot@1.0.0 start /var/www/path/to/myapp
> node ./bin/www
我可以在浏览器中成功看到该应用程序。
但是对于PM2 :
$ pm2 start /var/www/path/to/myapp/app.js
[PM2] Applying action restartProcessId on app [app](ids: 0)
[PM2] [app](0) ✓
[PM2] Process successfully started
┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ 0 │ fork │ 29210 │ online │ 0 │ 0s │ 12.383 MB │ disabled │
└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
我也尝试过这个:
$ cd /var/www/path/to/myapp
$ pm2 start app.js
它说该应用程序在线。 但是,当我尝试在浏览器上访问该应用程序时: http : //127.0.0.1 : 3000/
我收到此错误:
此网页无法使用
ERR_CONNECTION_REFUSED
与永远:
$ sudo forever start app.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: app.js
但是根本没有运气。
有什么想法我错过了吗?
编辑:
在package.json中:
{
"name": "iot",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"bcrypt": "^0.8.7",
"body-parser": "~1.15.1",
"connect-mongo": "^1.2.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.14.0",
"express-session": "^1.13.0",
"hat": "0.0.3",
"rand-token": "^0.2.1",
"method-override": "^2.3.6",
"mongoose": "^4.5.1",
"morgan": "~1.7.0",
"pug": "~2.0.0-beta3",
"serve-favicon": "~2.3.0"
}
}
如果我删除"scripts"
并运行npm update
:
{
"name": "iot",
"version": "1.0.0",
"private": true,
"dependencies": {
"bcrypt": "^0.8.7",
"body-parser": "~1.15.1",
"connect-mongo": "^1.2.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.14.0",
"express-session": "^1.13.0",
"hat": "0.0.3",
"rand-token": "^0.2.1",
"method-override": "^2.3.6",
"mongoose": "^4.5.1",
"morgan": "~1.7.0",
"pug": "~2.0.0-beta3",
"serve-favicon": "~2.3.0"
}
}
然后,我再次手动启动应用程序,但出现错误:
$ npm start
npm ERR! Linux 3.13.0-76-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v5.10.1
npm ERR! npm v3.8.3
npm ERR! missing script: start
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
问题是由express-generator引起的,我用它来生成我的应用程序项目!
它有一个运行http的bin
文件夹。 所以我必须先cd bin
然后pm2 start www
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.