在 Heroku 上设置 node.js 服务器的端口

在 Heroku 上设置 node.js 服务器的端口

问题描述:

我使用以下行启动了一个 node.js 服务器来设置端口:

I launched a node.js server with the following line to set the port:

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

这意味着,它应该读取 PORT 环境变量或默认为 8080,就像它在本地运行时一样.Heroku 上没有发生这两种情况,服务器始终使用默认端口 80.知道如何更改它吗?

This means that, it should either read the PORT env variable or default to 8080, as it does when it's run locally. Neither of them is happening on Heroku, and the server always uses the default port 80. Any idea how to change it?

heroku config
PORT: 8080

你不能.Heroku 设置您应该绑定的 PORT 变量,并在 tcp/80 上侦听.

You can't. Heroku sets the PORT variable that you are supposed to bind, and listens on tcp/80.