Heroku/Nodejs 启动失败,at=error code=H10 desc="App

LTF*_*eal 3 heroku mongodb node.js

我知道这已经被问过几次了,但我还没有找到有效的解决方案。我正在尝试将我的节点服务器部署在 Heroku 上并成功构建,但日志会打印以下消息。我也在使用猫鼬并且在本地部署没有问题。

2019-02-10T22:30:09.912634+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=chatifydotcom.herokuapp.com request_id=b486e511-ff21-4166-ae1d-07bf5796691e fwd="74.196.2.211" dyno= connect= service= status=503 bytes= protocol=https
Run Code Online (Sandbox Code Playgroud)

2019-02-10T22:30:10.287542+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=chatifydotcom.herokuapp.com request_id= 18f17ca0-56df-4dfe-a560-d890a699f17f fwd="74.196.2.211" dyno=connect=service=status=503 bytes=protocol=https

服务器.js

 const uri = process.env.MONGODB_URI || "mongodb://localhost:27017/chat"
mongoose
  .connect(uri, { useNewUrlParser: true })
  .then(() => console.log("MongoDB Connected"))
  .catch(err => console.log(err.message))

    const port = process.env.PORT || 9000
server.listen(port, () => {
  console.log(`This server is over ${port}`)
})
Run Code Online (Sandbox Code Playgroud)

You*_*hod 10

I'm working on this same error right now. The Heroku error code H10 essentially just means the app crashed, as it says, but you need to do more digging to figure out what the actual problem is.

You can do that by starting app on a heroku dyno from the console: EDIT: command for running the console may vary, I did this on Windows

heroku run bash
npm start
Run Code Online (Sandbox Code Playgroud)

Then you can see the console output of your app, and more specific error info for troubleshooting. Then you can fix or ask a more specific question on here.