[英]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.