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

时间:2023-02-01 18:14:38

I'm running a basic Express app in Node.js and trying to deploy to Heroku. The app works fine locally and I believe my setup with Heroku has gone well up until starting the server where i get the following error:

我在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

this is currently all i have in my app.js

这是我在app.js中的所有内容

app.listen(3000);

I did also run this as mentioned on Heroku's getting started.

我也像Heroku开始时提到的那样运行它。

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

I believe I just need to set up the port for production? Thanks.

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

1 个解决方案

#1


74  

Can you show the entire section of code where you call listen? You should be checking for the process environment variable PORT, not just hardcoding it to 3000. From their docs:

你可以显示你调用listen的整段代码吗?您应该检查进程环境变量PORT,而不仅仅是将其硬编码为3000.从他们的文档中:

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

#1


74  

Can you show the entire section of code where you call listen? You should be checking for the process environment variable PORT, not just hardcoding it to 3000. From their docs:

你可以显示你调用listen的整段代码吗?您应该检查进程环境变量PORT,而不仅仅是将其硬编码为3000.从他们的文档中:

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