Heroku的Nodejs端口错误 [英] Nodejs port error with Heroku

查看:108
本文介绍了Heroku的Nodejs端口错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的应用程序推送到heroku bu我遇到了这个问题,我正在使用使用process.env.PORT变量的正确端口号,但仍然收到以下错误消息:

I am trying to push my app to heroku bu I am getting this problem where I am using the correct port number using the process.env.PORT variable but still I am getting this error message:

heroku[web.1]:  Starting process with command `node app.js`
app[web.1]:     info  - socket.io started
app[web.1]: Express server listening on port 49559 in development mode
heroku[web.1]:  Error R11 (Bad bind) -> Process bound to port 10843, should be 49559 (see environment variable PORT)
heroku[web.1]:  Stopping process with SIGKILL
heroku[web.1]:  Process exited

您可以在此错误消息中看到该应用程序正在使用正确的端口,但仍然显示错误绑定错误。任何帮助表示赞赏。

You can see in this error message that app is using the right port but still heroku shows the bad bind error. Any help is appreciated.

推荐答案

PORT 的环境变量传递端口,这意味着您可以通过进程访问它.env

只需将您的代码更改为使用正确的端口号 listen / p>

Simply change your code to call listen with the proper port

var port = process.env.PORT || 3000;
app.listen(port);

这篇关于Heroku的Nodejs端口错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆