首页 > 解决方案 > heroku 应用程序错误,应用程序崩溃 Node.js

问题描述

我有一个连接到猫鼬的快速应用程序,这是我的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"
  }
}

和我的 procfile

网络:节点 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.jsexpresscrashhostingheroku-cli

解决方案


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

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

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

heroku config:set myEnvironmentVariable=234234

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

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

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

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


推荐阅读