node.js - 尝试打开 heroku 应用程序时出现应用程序错误消息

标签 node.js heroku

我是 Nodejs 新手,正在尝试将一个简单的文字游戏部署到 Heroku。我按照heroku网站上的说明进行操作,一切正常,直到最后一个命令“heroku open”,它打开一个网络浏览器并显示以下消息:

“应用程序发生错误,无法提供您的页面。请稍后重试。

如果您是应用程序所有者,请检查您的日志以了解详细信息。”

heroku 日志显示:

2016-08-04T18:56:36.552635+00:00 heroku[api]: Enable Logplex by teamsky916@gmail       .com
2016-08-04T18:56:36.552635+00:00 heroku[api]: Release v2 created by teamsky916@g       mail.com
2016-08-04T18:58:34.328360+00:00 heroku[router]: at=info code=H81 desc="Blank ap       p" method=GET path="/" host=build-word-game.herokuapp.com request_id=f238942c-ef       aa-4011-b505-7e5f062221a3 fwd="107.77.75.83" dyno= connect= service= status=502        bytes=
2016-08-04T18:58:35.171645+00:00 heroku[router]: at=info code=H81 desc="Blank ap       p" method=GET path="/favicon.ico" host=build-word-game.herokuapp.com request_id=       a02c27ef-865c-48e3-91cd-bd6e29ca51e3 fwd="107.77.75.83" dyno= connect= service=        status=502 bytes=
2016-08-04T19:26:43.069903+00:00 heroku[api]: Scale to web=1 by teamsky916@gmail       .com
2016-08-04T19:26:43.070467+00:00 heroku[api]: Deploy 4725c48 by teamsky916@gmail       .com
2016-08-04T19:26:43.070552+00:00 heroku[api]: Release v3 created by teamsky916@g       mail.com
2016-08-04T19:26:43.473784+00:00 heroku[slug-compiler]: Slug compilation finishe       d
2016-08-04T19:26:43.473765+00:00 heroku[slug-compiler]: Slug compilation started
2016-08-04T19:26:45.915539+00:00 heroku[web.1]: Starting process with command `n       ode server.js`
2016-08-04T19:26:50.481084+00:00 app[web.1]: listening to port 3000!
2016-08-04T19:27:46.488886+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web        process failed to bind to $PORT within 60 seconds of launch
2016-08-04T19:27:46.488886+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-08-04T19:27:46.631684+00:00 heroku[web.1]: Process exited with status 137
2016-08-04T19:27:46.618404+00:00 heroku[web.1]: State changed from starting to c       rashed
2016-08-04T19:27:46.619564+00:00 heroku[web.1]: State changed from crashed to st       arting
2016-08-04T19:27:48.599634+00:00 heroku[web.1]: Starting process with command `n       ode server.js`
2016-08-04T19:27:51.304417+00:00 app[web.1]: listening to port 3000!
2016-08-04T19:28:48.755864+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web        process failed to bind to $PORT within 60 seconds of launch
2016-08-04T19:28:48.755938+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-08-04T19:28:48.879934+00:00 heroku[web.1]: Process exited with status 137
2016-08-04T19:28:48.893371+00:00 heroku[web.1]: State changed from starting to c       rashed
2016-08-04T19:31:31.210359+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/" host=build-word-game.herokuapp.com request_id=e0536d30       -8590-453d-9a04-fb8a56eb6893 fwd="107.77.213.153" dyno= connect= service= status       =503 bytes=
2016-08-04T19:31:32.552715+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/favicon.ico" host=build-word-game.herokuapp.com request_       id=89bfb417-9793-4687-b400-72cc34d16ea8 fwd="107.77.213.153" dyno= connect= serv       ice= status=503 bytes=
2016-08-04T19:53:16.445270+00:00 heroku[web.1]: State changed from crashed to st       arting
2016-08-04T19:53:18.025971+00:00 heroku[web.1]: Starting process with command `n       ode server.js`
2016-08-04T19:53:19.981109+00:00 app[web.1]: listening to port 3000!
2016-08-04T19:54:18.509309+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-08-04T19:54:18.509204+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web        process failed to bind to $PORT within 60 seconds of launch
2016-08-04T19:54:18.601875+00:00 heroku[web.1]: Process exited with status 137
2016-08-04T19:54:18.606261+00:00 heroku[web.1]: State changed from starting to c       rashed
2016-08-04T19:59:58.452903+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/" host=build-word-game.herokuapp.com request_id=450b80d9       -a366-4e0f-9426-ff89eac931fb fwd="107.77.213.153" dyno= connect= service= status       =503 bytes=
2016-08-04T19:59:59.109794+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/favicon.ico" host=build-word-game.herokuapp.com request_       id=1eecc47a-5334-4a38-bd8d-093a9164ead5 fwd="107.77.213.153" dyno= connect= serv       ice= status=503 bytes=
2016-08-04T20:01:28.744667+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/" host=build-word-game.herokuapp.com request_id=a2d52aea       -d7fc-4f18-b023-50aa8e93587c fwd="107.77.213.153" dyno= connect= service= status       =503 bytes=
2016-08-04T20:01:29.378063+00:00 heroku[router]: at=error code=H10 desc="App cra       shed" method=GET path="/favicon.ico" host=build-word-game.herokuapp.com request_       id=8e62ab9c-50a3-43eb-9579-9c3d4a6c9d42 fwd="107.77.213.153" dyno= connect= serv       ice= status=503 bytes=

感谢您的帮助。

最佳答案

您的 Node 应用程序似乎未正常启动。这可能是由于您没有将 Node 服务器绑定(bind)到正确的端口。

在 Heroku 上,您必须将 Node 服务器绑定(bind)到 PORT 环境变量中指定的端口号。这是因为 Heroku 在具有许多其他应用程序的服务器上神奇地处理您的请求的路由。

您应该做的是修改您的 Node 代码,以便它监听端口 process.env.PORT

下面是一个监听正确端口的 Express.js 应用程序示例:

var express = require('express');

var app = express();

app.listen(process.env.PORT);

关于node.js - 尝试打开 heroku 应用程序时出现应用程序错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38776758/

相关文章:

javascript - 监控 Node.js 进程以了解每个进程的最大内存使用量

node.js - 如何在Lambda函数中访问API网关请求模型?

heroku - "bash: play: command not found"第一次尝试heroku时

ruby-on-rails - Rails 4 自定义 404 导致 Heroku 上的 postgresql 连接失败

ruby-on-rails-3 - Heroku - New Relic Agent 未在 rake db 上运行错误 :migrate

node.js - Nodejs 错误没有回溯

javascript - 赫罗库 : Firebase can't load credentials

node.js - Emit 和 on - Node JS 在函数内的单独模块中

node.js - 将meteor应用程序部署到heroku时,METEOR_SETTINGS is not valid json错误

git - 开源迷你 heroku?