在 Nodejs 上获取"Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of



我正在使用express在NodeJS上开发API,在尝试将其部署到Heroku时收到此错误:

错误 R10(启动超时)> Web 进程在启动后 60 秒内无法绑定到$PORT

我正在使用 process.env.PORT 变量,正如我在 SO 上找到的那样,但它仍然不起作用。下面是索引.js代码:

var express = require('express');
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.json());
var router = require("./router");
app.use('/viatges', router);
app.listen(3000 || process.env.PORT,function(){
console.log("up and running on port "+process.env.PORT);
});

您知道可能导致此问题的原因吗?

在 heroku 日志上,我看到这一行

2017-04-01T11:44:07.091181+00:00 app[web.1]:在端口 27583 上启动并运行

所以我假设 PORT 环境变量设置正确...

没关系,我刚刚修复了它。我更改了OR中操作数的顺序,我假设javascript只是按照定义的第一个操作数。

它现在看起来像这样:

app.listen(process.env.PORT || 3000 ,function(){
console.log("up and running on port "+process.env.PORT);
});

相关内容

最新更新