Node.js application keeps crashing on Heroku, gives error Boot timeout

帅比萌擦擦* 提交于 2019-12-11 06:10:08

问题


I'm developing a sample node.js application and it runs fine locally with

node index.js

but, when I push it to a Heroku instance, it crashes with the following errors:

2017-10-23T06:08:07.000000+00:00 app[api]: Build succeeded
2017-10-23T06:08:16.591817+00:00 heroku[web.1]: Starting process with command node --debug=5858 index.js
2017-10-23T06:08:17.873171+00:00 app[web.1]: Debugger listening on [::]:5858
2017-10-23T06:08:18.051769+00:00 app[web.1]: Server listening on port 8080
2017-10-23T06:09:16.966905+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2017-10-23T06:09:16.966905+00:00 heroku[web.1]: Stopping process with SIGKILL
2017-10-23T06:09:17.062360+00:00 heroku[web.1]: Process exited with status 137
2017-10-23T06:09:17.107893+00:00 heroku[web.1]: State changed from starting to crashed
2017-10-23T06:09:20.068453+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/contact" host=obscure-meadow-84857.herokuapp.com request_id=69c587a7-ba7f-49d3-8057-4b56338b2d01 fwd="49.35.12.63" dyno= connect= service= status=503 bytes= protocol=https
2017-10-23T06:09:20.137463+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=obscure-meadow-84857.herokuapp.com request_id=44f48e7a-94aa-4c10-9578-e8f50f8aeec5 fwd="49.35.12.63" dyno= connect= service= status=503 bytes= protocol=https

My package.json file is set up as follows:

{
  "name": "testapp",
  "version": "1.0.0",
  "description": "A little test application",
  "main": "basicRouting.js",
  "dependencies": {
    "ejs": "^2.5.7",
    "express": "^4.16.2"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "keywords": [
    "tutorial"
  ],
  "author": "Debaditya Dey",
  "license": "ISC"
}

Can anyone please help me out regarding this?


回答1:


2017-10-23T06:09:16.966905+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

Please use process.env.PORT for your app instead of using your own.




回答2:


In your index.js file, Define your port like this

const port = process.env.PORT || 8080;
app.listen(port, () => {
    console.log("Server listening on port " + port);
});


来源:https://stackoverflow.com/questions/46883036/node-js-application-keeps-crashing-on-heroku-gives-error-boot-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!