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

标签 node.js express heroku

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

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

我正在使用 process.env.PORT 变量,正如我在此处找到的那样,但它仍然无法正常工作。这是index.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]: up and running on port 27583

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

最佳答案

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

现在看起来像这样:

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

关于node.js - 在 Nodejs 上获取 "Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43156498/

相关文章:

javascript - 使用react-native通过TCP Socket发送mp3文件

node.js - 有没有办法在动态嵌入对象上使用聚合或 $sum ?

javascript - ExpressJS 和 Cookie - 无法获取 express-cookie 来初始化 Cookie

node.js - 一种在 Mongoose 中与用户加入帖子的方法

heroku - 你如何向 Heroku 项目添加一个 worker dyno?

node.js - 在 Docker 上构建 vue/quasar 应用程序时出错

javascript - Node.js HTTP GET “ECONNRESET” 读取错误

javascript - 为什么我的 body 在从 React JS 前端进行 post 调用时总是空的

windows - 如何编辑我的 .git/config 文件?

ruby-on-rails - 在 Heroku、Cedar 和 Unicorn 上:Getting ActiveRecord::StatementInvalid: PGError: SSL SYSCALL error: EOF detected