【问题标题】:Heroku app crashed h10 when deploying node js appHeroku 应用程序在部署节点 js 应用程序时崩溃了 h10
【发布时间】:2021-04-13 04:08:38
【问题描述】:

我正在尝试将简单的 CRUD 节点 js API 部署到 heroku,但总是让应用程序崩溃 h10,

它在本地https://i.stack.imgur.com/56GNF.png 中工作。但是当我部署它时出现此错误https://i.stack.imgur.com/KbZzJ.png

过程文件

web:node app.js

我已经尝试过web: node app.jsweb: yarn startweb:yarn start,但仍然遇到同样的错误

Package.JSON

{
  "name": "servis-invoice",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "dev": "nodemon app.js",
    "start": "node app.js"
  },
  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.11.18",
    "mongoose-delete": "^0.5.3",
    "nodemon": "^2.0.7"
  }
}

我的配置变量:https://i.stack.imgur.com/K7f0K.jpg

我是否缺少任何步骤?

我正在使用 yarn,但我不知道为什么 heroku 在部署中使用 npm start?

【问题讨论】:

  • 我的Procfile 看起来像这样:worker: node index.js。也许它对你有用

标签: node.js heroku devops


【解决方案1】:

在日志中,您会看到(著名的)错误web process failed to bind to $port,这意味着您的应用程序没有绑定到 Heroku 提供的端口

使用process.env.PORT 定义应用程序监听的端口

参见Heroku: Why is my Node.js app crashing with an R10 error?NodeJS 文档

【讨论】:

    猜你喜欢
    • 2019-11-02
    • 1970-01-01
    • 2019-12-05
    • 2020-08-25
    • 1970-01-01
    • 2020-09-24
    • 2016-03-07
    • 2021-01-07
    • 1970-01-01
    相关资源
    最近更新 更多