Can I have node.js listen on a non-standard port when hosted on Heroku?

不想你离开。 提交于 2020-01-21 11:32:46

问题


I'm building a node.js app and am experimenting with hosting it on Heroku. It seems that to make my app available to the world, I need to listen like this:

app.listen(process.env.PORT || 3000);

I'd like to have my app listen on port 8080. Is this possible in Heroku? Can I change the value of process.env.port? It seems to be some kind of reverse proxy that I might not have control over.


回答1:


No. Heroku tells your application which port your application is required to listen on. The required interface between Heroku and your application is the PORT environment variable: your application must look for and use it. Your application is not able to listen on any other port except the port that Heroku tells your application it must listen on. Heroku tries to open a TCP connection to your application on that port and, if sixty seconds elapse since Heroku started your application and your application isn't listening on that port, Heroku figures your application is broken and shuts it down.



来源:https://stackoverflow.com/questions/7459166/can-i-have-node-js-listen-on-a-non-standard-port-when-hosted-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!