与Heroku Nodejs端口错误

我想推我的应用程序到heroku埠我得到这个问题,我正在使用正确的端口号使用process.env.PORTvariables,但仍然收到此错误消息:

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 

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

Heroku将通过名为PORT的环境variables传递PORT ,这意味着您可以通过process.env访问它。

只需更改您的代码,使用正确的端口调用listen

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

我相信你正在使用使用端口10843的闪存套接字,并且该端口不是分配给应用程序的端口,你需要设置:

 io.configure(function () { io.set('transports', ['xhr-polling']); io.set("polling duration", 10); });