Heroko应用程序错误与节点js

时间:2016-08-04 14:36:44

标签: javascript node.js heroku

第一次使用Heroko。按照步骤,我的构建成功,但当我转到URL时,我收到了一个应用程序错误。我查看了日志,但我不确定发生了什么,下面是我的日志列表

    2016-08-04T14:24:15.352519+00:00 heroku[web.1]: State changed from crashed to starting
2016-08-04T14:24:31.776384+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-08-04T14:24:34.211793+00:00 app[web.1]: keyword api listening at http://[::]:8088
2016-08-04T14:25:32.328147+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-08-04T14:25:32.327930+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-08-04T14:25:32.501167+00:00 heroku[web.1]: State changed from starting to crashed
2016-08-04T14:25:32.503024+00:00 heroku[web.1]: State changed from crashed to starting
2016-08-04T14:25:32.477573+00:00 heroku[web.1]: Process exited with status 137
2016-08-04T14:25:36.445941+00:00 heroku[web.1]: Starting process with command `node server.js`
2016-08-04T14:25:39.335482+00:00 app[web.1]: keyword api listening at http://[::]:8088
2016-08-04T14:26:37.186681+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-08-04T14:26:37.186681+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-08-04T14:26:37.329330+00:00 heroku[web.1]: Process exited with status 137
2016-08-04T14:26:37.353704+00:00 heroku[web.1]: State changed from starting to crashed
2016-08-04T14:26:37.619772+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=shielded-temple-17247.herokuapp.com request_id=db8eb419-e950-4768-8a3f-319a84f7d4e2 fwd="2.125.30.1" dyno= connect= service= status=503 bytes=
2016-08-04T14:26:38.809203+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=shielded-temple-17247.herokuapp.com request_id=5661b532-80af-40cb-8ae3-0bf9868b5e0f fwd="2.125.30.1" dyno= connect= service= status=503 bytes=

1 个答案:

答案 0 :(得分:0)

您在Procfile中定义了什么?现在,它似乎是这样的:

web: node server.js

Procfile告诉Heroku如何运行您的应用程序。您显示的日志表明您尝试在端口8088上运行节点服务器 - 这可能是问题所在。

Heroku不允许您在所需的任何端口上运行服务器 - 相反,它会动态地告诉您在应用程序启动时运行服务器的端口。它通过使用名为PORT的环境变量来实现这一点。

您需要做的是修改server.js代码,以便在process.env.PORT上启动服务器。

这是一个例子(在express.js中):

var express = require('express');

var app = express();

app.listen(process.env.PORT);

这将通过自动绑定到正确的端口成功启动Heroku上的节点服务器。

希望有所帮助!