gpt4 book ai didi

node.js - heroku 应用程序错误,应用程序崩溃 Node.js

转载 作者:行者123 更新时间:2023-12-03 16:59:22 27 4
gpt4 key购买 nike

我有一个连接到 Mongoose 的快速应用程序是我的包.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

web : node 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;

最佳答案

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

  • 我有一个名为 https-localHost 的 npm 模块
    当您想要测试时,它会为您提供 ssl 让我们说使用 facebook、google 或任何其他 OAuth 进行身份验证
    其解决方案是 只需卸载模块或 停止使用它
  • 我没有设置环境变量
    您可以在控制台上使用此命令
  • heroku config:set myEnvironmentVariable=234234
  • 由于我使用的是 mongodb,heroku 上的应用程序无法连接到我电脑上的本地实例,所以我不得不再次使用环境变量从 Mlab 提供一个

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

    winston is designed to be a simple and universal logging library with support for multiple transports. A transport is essentially a storage device for your logs.



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

    关于node.js - heroku 应用程序错误,应用程序崩溃 Node.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58403668/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com