【问题标题】:Why am I still getting R10 error when trying to deploy an Express app为什么在尝试部署 Express 应用程序时仍然出现 R10 错误
【发布时间】:2020-01-19 22:06:50
【问题描述】:

我正在尝试在 Heroku 上托管 Express 应用程序,但我不断收到错误消息:Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

当我试图找到解决方案时,我发现一堆页面说 heroku dynos 使用动态端口,并且可以使用process.env.PORT 访问它,并且您必须在地址0.0.0.0 上收听.我已经完成了这两件事,并且程序记录了我认为启动时正确的端口,但它仍然给了我错误。我发现在修复端口后仍然出现此错误的所有人都已经弄清楚如何修复它,或者遇到了其他不适用于此处的问题。

目前,我只是尝试托管一个简单的程序,其代码如下所示。

const express = require("express")
let app = express()

app.get("/", (req,res) => {
    res.send("testing")
})

const PORT = (process.env.PORT | 8080)

app.listen(PORT, "0.0.0.0", () => {
    console.log(`listening on port *: ${PORT}`)
})

【问题讨论】:

  • 运行时是否设置了process.env.PORT?

标签: node.js express heroku deployment


【解决方案1】:

这里的问题是(process.env.PORT | 8080)。

| 是按位或运算。

|| 是逻辑或运算。

你需要做const PORT = (process.env.PORT || 8080);

这里是一个简单的测试用例:

console.log(1234 |  8080)  // 8146
console.log(1234 || 8080) // 1234

【讨论】:

    猜你喜欢
    • 2014-09-16
    • 2019-01-29
    • 1970-01-01
    • 2019-11-11
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多