Heroku Node.js 错误 R10(启动超时)-> Web 进程未能在启动后 60 秒内绑定到 $PORT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31092538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:55:31  来源:igfitidea点击:

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

node.jsheroku

提问by fivepointseven

I found a dozen solutions for Express powered apps with setting port to listen on. But I have an app that doesn't use Express and doesn't in fact listens anything. And after 60 seconds of it successfully running I get a Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launchmessage. How I can get around it? Thanks.

我为 Express 驱动的应用程序找到了十几种解决方案,并设置了侦听端口。但我有一个不使用 Express 的应用程序,实际上什么也不听。在它成功运行 60 秒后,我收到一条Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch消息。我怎样才能解决它?谢谢。

回答by fivepointseven

After lots of googling I decided to npm install expressand add

经过大量的谷歌搜索后,我决定npm install express添加

var express = require('express');
var app     = express();

app.set('port', (process.env.PORT || 5000));

//For avoidong Heroku $PORT error
app.get('/', function(request, response) {
    var result = 'App is running'
    response.send(result);
}).listen(app.get('port'), function() {
    console.log('App is running, server is listening on port ', app.get('port'));
});

This fixed the error, even though I don't like adding express just to avoid one error. If someone finds a better solution, please let me know.

这修复了错误,即使我不喜欢添加 express 只是为了避免一个错误。如果有人找到更好的解决方案,请告诉我。

回答by sergiy.dragunov

If your app doesn't listen any port then you should use another type of app in you Procfile, I mean in Procfile you have:

如果您的应用程序不侦听任何端口,那么您应该在 Procfile 中使用另一种类型的应用程序,我的意思是在 Procfile 中您有:

web: node app.js

replace it with:

替换为:

worker: node app.js

"web" type of application means that your app MUST listen some port

“网络”类型的应用程序意味着您的应用程序必须侦听某个端口

回答by Pille

Another way would be changing the dynos from web (standard setting regardless of the settings in Procfile) to worker with these commands:

另一种方法是使用以下命令将 dynos 从 web(标准设置,无论 Procfile 中的设置如何)更改为 worker:

heroku ps:scale web=0
heroku ps:scale worker=1

Sometimes Heroku ignores settings in the Procfile.

有时 Heroku 会忽略 Procfile 中的设置。

回答by Ferry Sanjaya

I have the same issue:

我有同样的问题:

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

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

I tried many things.

我尝试了很多东西。

The following works without using express:

以下工作不使用快递:

http.createServer(onRequest).listen(process.env.PORT || 6000)