使用“ heroku open”部署我的Node.js应用程序时出现“应用程序错误”

时间:2018-06-30 13:18:33

标签: node.js mongodb heroku

我制作了一个项目,特别是使用Node.js的URL Shortener,它在端口本地运行时可以完美运行。但是,在尝试使用heroku open命令通过Heroku推送它时,出现此错误:

Application error
An error occurred in the application and your page could not be served. If you 
are the application owner, check your logs for details.

使用命令heroku logs检查日志后,我得到了

2018-06-30T12:12:49.803878+00:00 heroku[web.1]: Error R10 (Boot timeout) -> 
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:12:49.803878+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:12:49.863059+00:00 heroku[web.1]: Process exited with status     
137
2018-06-30T12:12:49.917775+00:00 heroku[web.1]: State changed from starting 
to crashed
2018-06-30T12:12:50.752040+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=3c9d005b-1d44-4dd6-949f-e8569d11d6ce fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:12:53.135532+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=5831725a-1741-4de2-b584-1e93781acbb3 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:15:06.131305+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=52a81f50-a39a-447c-b5ff-6762306f6a30 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:15:07.638452+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=1442fbc5-b1c4-48d8-aaaa-b0d077a3c599 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:17:18.615544+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=e7174a54-81d7-41ad-be32-b24bdcc81058 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:17:20.204337+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=31beadca-550e-4465-9248-bbf249a3a3e5 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:19:59.481276+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=279bf7fa-620d-4f7f-a8df-1aed11b8e743 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:20:00.925705+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=f256ddc2-b25a-4e33-a286-e56ba883cdf0 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:22:32.739228+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=293c6632-7858-4cee-b027-bb9ac410dbf3 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:22:34.218261+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=d278275d-890a-4941-a7ad-1426d384369d fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:25:29.680329+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=c9c822d5-c0d0-4102-86f3-7cd25125056e fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:25:31.217264+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=797ff435-7bdb-4db7-83a7-8df3cf5c2c73 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:30:43.275158+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=988205da-18c6-4c0a-be94-74d3f0b9f580 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:30:44.718764+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=609ade39-ce5a-4099-bd7a-99ea7fe6acff fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:32:34.854123+00:00 heroku[web.1]: State changed from crashed to 
down
2018-06-30T12:32:34.732293+00:00 app[api]: Scaled to web@0:Free by user 
maan.vs97@gmail.com
2018-06-30T12:33:16.888301+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=3aa3ccc4-796d-4abb-bf21-85806f2f1419 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:33:18.353601+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=10fd0f3a-4301-405e-a0c9-ec64bcb5142d fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:33:49.923844+00:00 app[api]: Scaled to web@1:Free by user 
maan.vs97@gmail.com
2018-06-30T12:33:52.699604+00:00 heroku[web.1]: Starting process with command 
`node app.js`
2018-06-30T12:33:55.925804+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:33:55.980456+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to 
server [localhost:27017] on first connect [MongoNetworkError: connect 
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:33:55.980460+00:00 app[web.1]: at Pool.<anonymous> 
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:33:55.980463+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:33:55.980464+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:33:55.980468+00:00 app[web.1]: at Object.onceWrapper 
(events.js:317:30)
2018-06-30T12:33:55.980466+00:00 app[web.1]: at Connection.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:33:55.980469+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:33:55.980471+00:00 app[web.1]: at Connection.emit 
(events.js:214:7)
2018-06-30T12:33:55.980473+00:00 app[web.1]: at Socket.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:33:55.980474+00:00 app[web.1]: at Object.onceWrapper 
(events.js:315:30)
2018-06-30T12:33:55.980476+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:33:55.980477+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:33:55.980480+00:00 app[web.1]: at emitErrorNT 
(internal/streams/destroy.js:64:8)
2018-06-30T12:33:55.980482+00:00 app[web.1]: at _combinedTickCallback 
(internal/process/next_tick.js:138:11)
2018-06-30T12:33:55.980483+00:00 app[web.1]: at process._tickCallback 
(internal/process/next_tick.js:180:9)
2018-06-30T12:33:55.981085+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error 
originated either by throwing inside of an async function without a catch 
block, or by rejecting a promise which was not handled with .catch(). 
(rejection id: 1)
2018-06-30T12:33:55.981260+00:00 app[web.1]: (node:4) [DEP0018] 
DeprecationWarning: Unhandled promise rejections are deprecated. In the 
future, promise rejections that are not handled will terminate the Node.js 
process with a non-zero exit code.
2018-06-30T12:34:52.721215+00:00 heroku[web.1]: Error R10 (Boot timeout) -> 
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:34:52.721306+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:34:52.860272+00:00 heroku[web.1]: State changed from starting 
to crashed
2018-06-30T12:34:52.863587+00:00 heroku[web.1]: State changed from crashed to 
starting
2018-06-30T12:34:52.841500+00:00 heroku[web.1]: Process exited with status 
137
2018-06-30T12:34:54.755270+00:00 heroku[web.1]: Starting process with command 
`node app.js`
2018-06-30T12:34:56.835821+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:34:56.863257+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to 
server [localhost:27017] on first connect [MongoNetworkError: connect 
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:34:56.863262+00:00 app[web.1]: at Pool.<anonymous> 
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:34:56.863264+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:34:56.863265+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:34:56.863266+00:00 app[web.1]: at Connection.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:34:56.863267+00:00 app[web.1]: at Object.onceWrapper 
(events.js:317:30)
2018-06-30T12:34:56.863268+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:34:56.863269+00:00 app[web.1]: at Connection.emit 
(events.js:214:7)
2018-06-30T12:34:56.863271+00:00 app[web.1]: at Socket.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:34:56.863272+00:00 app[web.1]: at Object.onceWrapper 
(events.js:315:30)
2018-06-30T12:34:56.863273+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:34:56.863274+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:34:56.863275+00:00 app[web.1]: at emitErrorNT 
(internal/streams/destroy.js:64:8)
2018-06-30T12:34:56.863277+00:00 app[web.1]: at _combinedTickCallback 
(internal/process/next_tick.js:138:11)
2018-06-30T12:34:56.863278+00:00 app[web.1]: at process._tickCallback 
(internal/process/next_tick.js:180:9)
2018-06-30T12:34:56.863324+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error 
originated either by throwing inside of an async function without a catch 
block, or by rejecting a promise which was not handled with .catch(). 
(rejection id: 1)
2018-06-30T12:34:56.863396+00:00 app[web.1]: (node:4) [DEP0018] 
DeprecationWarning: Unhandled promise rejections are deprecated. In the 
future, promise rejections that are not handled will terminate the Node.js 
process with a non-zero exit code.
2018-06-30T12:35:11.726745+00:00 heroku[router]: at=error code=H20 desc="App 
boot timeout" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=68e14a23-255a-4c6d-99d6-525727a2b800 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:35:55.215653+00:00 heroku[web.1]: Error R10 (Boot timeout) -> 
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:35:55.215699+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:35:55.296657+00:00 heroku[web.1]: Process exited with status 
137
2018-06-30T12:35:55.314683+00:00 heroku[web.1]: State changed from starting 
to crashed
2018-06-30T12:35:56.892537+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=e9ed60ed-3dc5-42a8-86d8-e60942c803f5 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:36:01.869896+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=cd84ae69-d3c2-4ab1-892b-4dc933048c77 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:36:03.805047+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=b9455320-0f8e-4d28-8793-612d47635954 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T12:58:34.550597+00:00 heroku[web.1]: State changed from crashed to 
starting
2018-06-30T12:58:36.492786+00:00 heroku[web.1]: Starting process with command 
`node app.js`
2018-06-30T12:58:38.568708+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:58:38.590986+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to 
server [localhost:27017] on first connect [MongoNetworkError: connect 
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:58:38.590989+00:00 app[web.1]: at Pool.<anonymous> 
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:58:38.590991+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:58:38.590992+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:58:38.590993+00:00 app[web.1]: at Connection.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:58:38.590994+00:00 app[web.1]: at Object.onceWrapper 
(events.js:317:30)
2018-06-30T12:58:38.590995+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:58:38.590996+00:00 app[web.1]: at Connection.emit 
(events.js:214:7)
2018-06-30T12:58:38.590997+00:00 app[web.1]: at Socket.<anonymous> 
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:58:38.590999+00:00 app[web.1]: at Object.onceWrapper 
(events.js:315:30)
2018-06-30T12:58:38.591000+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:58:38.591001+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:58:38.591015+00:00 app[web.1]: at emitErrorNT 
(internal/streams/destroy.js:64:8)
2018-06-30T12:58:38.591017+00:00 app[web.1]: at _combinedTickCallback 
(internal/process/next_tick.js:138:11)
2018-06-30T12:58:38.591018+00:00 app[web.1]: at process._tickCallback 
(internal/process/next_tick.js:180:9)
2018-06-30T12:58:38.591063+00:00 app[web.1]: (node:4) 
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error 
originated either by throwing inside of an async function without a catch 
block, or by rejecting a promise which was not handled with .catch(). 
(rejection id: 1)
2018-06-30T12:58:38.591132+00:00 app[web.1]: (node:4) [DEP0018] 
DeprecationWarning: Unhandled promise rejections are deprecated. In the 
future, promise rejections that are not handled will terminate the Node.js 
process with a non-zero exit code.
2018-06-30T12:59:37.052499+00:00 heroku[web.1]: Error R10 (Boot timeout) -> 
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:59:37.052596+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:59:37.173301+00:00 heroku[web.1]: State changed from starting 
to crashed
2018-06-30T12:59:37.139128+00:00 heroku[web.1]: Process exited with status 
137
2018-06-30T13:00:15.376173+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/" host=maan-singh.herokuapp.com 
request_id=5449c1e7-e849-4192-a691-7a7c1e71f530 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https
2018-06-30T13:00:17.426839+00:00 heroku[router]: at=error code=H10 desc="App 
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com 
request_id=5b02acc8-7218-4bd3-8c3a-a8183000c363 fwd="103.47.59.2" dyno= 
connect= service= status=503 bytes= protocol=https

我的应用程序的链接地址为https://maan-singh.herokuapp.com/

我使用了本地MongoDB数据库项目,甚至尝试使用heroku open命令推送项目,无论是否从命令提示符启动MongoDB,但都没有用。在这种情况下,我没有使用GitHub存储库来推送代码,因为我的计算机中已有文件。这是错误的原因吗?

请让我知道需要更多信息。谢谢。

1 个答案:

答案 0 :(得分:0)

Web process failed to bind to $PORT within 

通常会出现错误,这意味着您已在主节点或索引节点js文件中分配了一个硬编码端口。这导致Heroku在启动时尝试将其选择的随机端口分配给您的节点应用程序时崩溃。因此,您的应用程序无法启动。

要解决此问题,您将必须为节点应用程序设置端口,如下所示。

const PORT = process.env.PORT || 3000; 
...
...
.listen(PORT); // START YOUR SERVER HERE

这将允许您在本地运行节点应用程序时在其上运行节点应用程序,并将此代码推送到Heroku时,它将为该错误分配一个随机端口。