【问题标题】:heroku application error, application crashed Node.jsheroku 应用程序错误,应用程序崩溃 Node.js
【发布时间】:2019-10-16 08:14:13
【问题描述】:

我有一个连接到猫鼬的快速应用程序,这是我的 package.json

{
  "name": "backend",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "^1.19.0",
    "cookie-parser": "^1.4.4",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "helmet": "^3.21.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.7.4",
    "morgan": "^1.9.1"
  }
}

和我的过程文件

web : 节点 app.js

and this is the error i get from the logs
2019-10-15T22:49:24.862621+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=boutique2backend.herokuapp.com request_id=7d85289
5-32ec-4958-84f9-4b6f1c185539 fwd="41.40.131.141" dyno= connect= service= status
=503 bytes= protocol=https
2019-10-15T22:49:25.325894+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=boutique2backend.herokuapp.com request
_id=1aa4b90e-040d-4cc0-9b79-b4cf28b2c804 fwd="41.40.131.141" dyno= connect= serv
ice= status=503 bytes= protocol=https

当我重新启动应用程序时,我得到

2019-10-15T22:50:07.470079+00:00 heroku[web.1]: State changed from crashed to st
arting
2019-10-15T22:50:09.525567+00:00 heroku[web.1]: Starting process with command `:
 node app.js`
2019-10-15T22:50:11.621514+00:00 heroku[web.1]: Process exited with status 0
2019-10-15T22:50:11.666391+00:00 heroku[web.1]: State changed from starting to c
rashed

我双重确保我的端口设置为 env 变量

const PORT = process.env.PORT || 3002;

【问题讨论】:

    标签: node.js express crash hosting heroku-cli


    【解决方案1】:

    这曾经发生在我身上,这些可能是罪魁祸首

    • 我有一个名为 https-localHost 的 npm 模块 当您想要测试时,它会为您提供 ssl,比如说使用 facebook、google 或任何其他 OAuth 进行身份验证 其解决方案是简单地卸载模块或停止使用它

    • 我没有设置环境变量 您可以使用此命令在控制台上执行此操作

    heroku config:set myEnvironmentVariable=234234

    • 由于我使用的是 mongodb,heroku 上的应用程序无法连接到我电脑上的本地实例,因此我不得不再次使用环境变量从 Mlab 提供一个

    我建议你使用winston 根据他们的说法

    winston 被设计成一个简单且通用的日志库,支持多种传输。传输本质上是日志的存储设备。

    它将允许您将错误存储在文件中,当您 ssh 进入或从 Heroku 仪表板中访问时,您可以从控制台访问这些文件,以便更好地查看错误并了解问题的根源,因为查看实际的heroku日志实际上不会向您显示这些错误 干杯!

    【讨论】:

    • 我安装了 winston 和 winston-express 以使用该中间件,它仅在我在我的机器上本地运行时才对我有效。当我在 herokuapp 上运行它时,它在使用它之前就崩溃了。
    猜你喜欢
    • 2014-10-22
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多