[英]PM2 doesn't work on NodeJS (Heroku)
我正在使用PM2讓NodeJS(Express)連續運行。 在我的本地計算機上,以下內容在我的packages.json中起作用:
"scripts": {
"start": "pm2 start ./bin/www"
}
之后,我使用“ npm start”運行我的應用程序。 這一切都很好。
現在,我想將我的應用程序部署到Heroku。 我用“ web:npm start”添加了一個Procfile。 之后,我將packages.json稍微更改為:
"scripts": {
"preinstall": "npm install pm2 -g",
"start": "pm2 start ./bin/www"
}
但是,我收到此錯誤:
2018-02-22T19:51:23.861641+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2018-02-22T19:51:23.862201+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-02-22T19:51:24.007776+00:00 heroku[web.1]: Process exited with status 137
2018-02-22T19:51:24.046849+00:00 heroku[web.1]: State changed from starting to crashed
我已經找到了解決此問題的許多方法,例如將Procfile更改為“ worker:node app.js”並運行命令:“ $ heroku scale web = 0 worker = 1”。
但是我找不到問題所在。 我認為這與“ pm2”模塊有關,因為當我不使用它時,我的應用程序可以正常工作。 但是,它會在短時間內崩潰。 希望有人可以幫助我。
“ pm2 show www”顯示如下:
│ status │ online │
│ name │ www │
│ restarts │ 151 │
│ uptime │ 40s │
│ script path │ /Users/user1/Documents/Weview/app/bin/www │
│ script args │ N/A │
│ error log path │ /Users/user1/.pm2/logs/www-error-1.log │
│ out log path │ /Users/user1/.pm2/logs/www-out-1.log │
│ pid path │ /Users/user1/.pm2/pids/www-1.pid │
│ interpreter │ node │
│ interpreter args │ N/A │
│ script id │ 1 │
│ exec cwd │ /Users/user1/Documents/Weview/app │
│ exec mode │ fork_mode │
│ node.js version │ 8.9.1 │
│ watch & reload │ ✘ │
│ unstable restarts │ 0 │
│ created at │ 2018-02-22T20:22:53.688Z │
└───────────────────┴──────────────────────────────────────────────────────────────┘
Code metrics value
┌─────────────────┬────────┐
│ Loop delay │ 2.86ms │
│ Active requests │ 0 │
│ Active handles │ 4
用這個
"scripts": {
"start": "PORT=3000 pm2 start ./bin/www"
}
Heroku嘗試使用環境變量PORT
綁定節點應用程序
首先,您必須安裝pm2。 我在這些文檔中閱讀
塞你的package.json
“ scripts”:{“ preinstall”:“ npm install pm2 -g”,“ start”:“ pm2-runtime app.js -i max”},
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.