Heroku cedar 堆栈上的 Node.js 端口问题

标签 node.js heroku port express

我正在 Node.js 中运行一个基本的 Express 应用程序并尝试部署到 Heroku。该应用程序在本地运行良好,我相信我与 Heroku 的设置进展顺利,直到启动服务器时出现以下错误:

2011-09-21T16:42:36+00:00 heroku[web.1]: State changed from created to starting
2011-09-21T16:42:39+00:00 app[web.1]: Express server listening on port 3000 in production mode
2011-09-21T16:42:40+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 3000, should be 12810 (see environment variable PORT)
2011-09-21T16:42:40+00:00 heroku[web.1]: Stopping process with SIGKILL
2011-09-21T16:42:40+00:00 heroku[web.1]: Process exited

这是目前我在 app.js 中的全部内容

app.listen(3000);

我也确实按照 Heroku 入门中提到的那样运行了这个。

$ heroku config:add NODE_ENV=production
Adding config vars:
NODE_ENV => production

我相信我只需要设置生产端口?谢谢。

最佳答案

您能否显示调用 listen 的整个代码部分?您应该检查进程环境变量 PORT,而不仅仅是将其硬编码为 3000。来自他们的 docs :

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

关于Heroku cedar 堆栈上的 Node.js 端口问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7503632/

相关文章:

node.js - Firestore 安全规则 : How to enforce the number of fields CREATED in a Firestore document thru security rules?

node.js - 如何将 NodeJS 应用程序部署到 Heroku?

mysql - 端口是如何工作的?

c - Linux API/库枚举特定IP的所有监听端口

node.js - Mocha beforeEach vs 执行前

javascript - 另一个 "can' t 在发送后设置 header ”

node.js - CURL - 如何传递 OAUTH2 Pingfederate 身份验证的用户名和密码?

django - 在本地机器上开发时如何访问在线 postgresql 数据库?

python - 无法在 Linux 上 pip 安装 psycopg2

Spring Boot : specify port at the mapping level