node.js - 尝试在heroku中部署 Node 应用程序时不断收到应用程序错误

标签 node.js heroku

我在 Heroku 上部署时遇到了困难。按照 Heroku 指南上的部署 Node js 应用程序进行操作,但仍然不断收到应用程序错误。知道为什么吗?这是我的 Heroku 日志

 heroku logs
2015-10-27T19:48:35.704758+00:00 heroku[api]: Enable Logplex by chineduabalogu@gmail.com
2015-10-27T19:48:35.704758+00:00 heroku[api]: Release v2 created by chineduabalogu@gmail.com
2015-10-27T19:57:58.536860+00:00 heroku[slug-compiler]: Slug compilation started
2015-10-27T19:57:58.536871+00:00 heroku[slug-compiler]: Slug compilation finished
2015-10-27T19:57:58.397214+00:00 heroku[api]: Scale to web=1 by chineduabalogu@gmail.com
2015-10-27T19:57:58.466140+00:00 heroku[api]: Deploy 51bdb1d by chineduabalogu@gmail.com
2015-10-27T19:57:58.466140+00:00 heroku[api]: Release v3 created by chineduabalogu@gmail.com
2015-10-27T19:58:00.692453+00:00 heroku[web.1]: Starting process with command `npm start`
2015-10-27T19:58:03.827532+00:00 app[web.1]: 
2015-10-27T19:58:03.827554+00:00 app[web.1]: > node app.js
2015-10-27T19:58:03.827552+00:00 app[web.1]: > gf17@0.0.1 start /app
2015-10-27T19:58:03.827555+00:00 app[web.1]: 
2015-10-27T19:58:04.616168+00:00 app[web.1]: Express server listening on port 3000
2015-10-27T19:59:00.972722+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-10-27T19:59:00.972722+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-10-27T19:59:01.940288+00:00 heroku[web.1]: State changed from starting to crashed
2015-10-27T19:59:01.941567+00:00 heroku[web.1]: State changed from crashed to starting
2015-10-27T19:59:01.932037+00:00 heroku[web.1]: Process exited with status 137
2015-10-27T19:59:04.247002+00:00 heroku[web.1]: Starting process with command `npm start`
2015-10-27T19:59:07.923766+00:00 app[web.1]: 
2015-10-27T19:59:07.923776+00:00 app[web.1]: > gf17@0.0.1 start /app
2015-10-27T19:59:07.923778+00:00 app[web.1]: > node app.js
2015-10-27T19:59:07.923779+00:00 app[web.1]: 
2015-10-27T19:59:09.513389+00:00 app[web.1]: Express server listening on port 3000
2015-10-27T20:00:04.705994+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-10-27T20:00:04.705994+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-10-27T20:00:05.657468+00:00 heroku[web.1]: State changed from starting to crashed
2015-10-27T20:00:05.644215+00:00 heroku[web.1]: Process exited with status 137
2015-10-27T20:17:45.559370+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-fjord-8286.herokuapp.com request_id=ce9f7865-5431-4514-83e3-9228df351291 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:17:46.110795+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-fjord-8286.herokuapp.com request_id=e7b1f9b7-4600-4ce7-b90c-3239a82abcb9 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:17:48.086903+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-fjord-8286.herokuapp.com request_id=8a41518c-cfd8-4dac-8622-1f94de9346b3 fwd="198.15.118.148" dyno= connect= service= status=503 bytes=
2015-10-27T20:17:48.543167+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-fjord-8286.herokuapp.com request_id=e1ce271b-7a76-43c1-931e-0ac9a375cfb7 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:19:48.784831+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-fjord-8286.herokuapp.com request_id=9229308a-6604-4426-8ba6-4cabb8b94de9 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:19:49.552910+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-fjord-8286.herokuapp.com request_id=e542cc92-ca00-4044-8c23-76642887ef35 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:22:17.304691+00:00 heroku[web.1]: State changed from crashed to starting
2015-10-27T20:22:19.261727+00:00 heroku[web.1]: Starting process with command `npm start`
2015-10-27T20:22:21.447920+00:00 app[web.1]: 
2015-10-27T20:22:21.447934+00:00 app[web.1]: > gf17@0.0.1 start /app
2015-10-27T20:22:21.447935+00:00 app[web.1]: > node app.js
2015-10-27T20:22:21.447936+00:00 app[web.1]: 
2015-10-27T20:22:22.123539+00:00 app[web.1]: Express server listening on port 3000
2015-10-27T20:23:19.916089+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-10-27T20:23:19.916089+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-10-27T20:23:20.780482+00:00 heroku[web.1]: Process exited with status 137
2015-10-27T20:23:20.792567+00:00 heroku[web.1]: State changed from starting to crashed
2015-10-27T20:25:54.984210+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=evening-fjord-8286.herokuapp.com request_id=83eec29d-598c-44d1-b6bc-55933e60013f fwd="154.118.30.203" dyno= connect= service= status=503 bytes=
2015-10-27T20:25:56.659875+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=evening-fjord-8286.herokuapp.com request_id=c384f7e6-e6e9-4088-bdf1-b7370b572b68 fwd="154.118.30.203" dyno= connect= service= status=503 bytes=

最佳答案

从您的日志来看,您似乎没有绑定(bind)到正确的端口。

我假设您的 Express.js 应用程序如下所示:

app.listen(3000);

这行代码告诉 Express.js 开始在端口 3000 上运行 Web 服务器。当您在笔记本电脑上编写代码时,这很好,但是当您将代码部署到 Heroku 时,Heroku 将为您分配一个您必须绑定(bind)到的随机端口号。

因此,要解决您的问题,您应该重写上面的代码行,如下所示:

app.listen(process.env.PORT || 3000);

这将告诉您的应用程序在正确的 Heroku 端口上运行,但在本地笔记本电脑上进行开发时回退到端口 3000 =) 这是两全其美的。

希望这有帮助!

关于node.js - 尝试在heroku中部署 Node 应用程序时不断收到应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33378161/

相关文章:

node.js - Mongo gridfs-stream

heroku - 使用 Ruppell 的 Sockets 插件在 Heroku 上托管 TCP 服务器时出现 "Connection closed by foreign host"错误

ruby-on-rails - 将带有 React 组件的 Ruby on Rails 项目部署到 Heroku

Heroku 应用程序名称更改后 Git 推送失败

python - ImportError: 仅当在 heroku 上部署 django 应用程序时才出现 win32

node.js - 在 Node/Express 上启用 CORS 不起作用

node.js - 在查询字符串 node.js 中传递对象数组

node.js - 中间件和 NodeJS 错误

java - 使用 Java 在 MongoDB 中更新集合。

node.js - 无法在 Express.js 中使用 connect-redis