Heroku cedar 堆栈上的 Node.js 端口问题
我正在 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
我相信我只需要设置用于生产的端口?谢谢。
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:
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.listen(3000);
I did also run this as mentioned on Heroku's getting started.
$ 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能显示调用
listen
的整个代码部分吗?您应该检查进程环境变量 PORT,而不仅仅是将其硬编码为 3000。来自他们的 docs: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: