在 Heroku 上设置 node.js 服务器的端口 [英] Setting the port for node.js server on Heroku

查看:36
本文介绍了在 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.

这篇关于在 Heroku 上设置 node.js 服务器的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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