【问题标题】:Port in use when launching Node.js app with Heroku Foreman使用 Heroku Foreman 启动 Node.js 应用程序时使用的端口
【发布时间】:2013-10-01 10:40:37
【问题描述】:

我正在尝试将我的 node.js 应用程序部署到 heroku,但是当我尝试使用工头在本地启动它时出现错误:听 EADDRINUSE。我已经运行了一个 netstat 并 grepped 了端口,没有其他任何东西在使用它,并且当直接作为节点 http 服务器运行时,服务器启动没有问题。

我尝试部署的应用程序正在使用 mongo 和 redis 我不确定这些组件是否会影响从 Foreman 开始的服务器。有人对我可以查看潜在错误的区域有任何建议吗?

foreman start
01:37:18 web.1  | started with pid 1835
01:37:18 web.1  | /usr/local/foreman/lib/foreman/process.rb:66: warning: Insecure world writable dir /usr/local in PATH, mode 040777
01:37:19 web.1  | events.js:72
01:37:19 web.1  |         throw er; // Unhandled 'error' event
01:37:19 web.1  |               ^
01:37:19 web.1  | Error: listen EADDRINUSE
01:37:19 web.1  |     at errnoException (net.js:863:11)
01:37:19 web.1  |     at Server._listen2 (net.js:1008:14)
01:37:19 web.1  |     at listen (net.js:1030:10)
01:37:19 web.1  |     at Server.listen (net.js:1096:5)
01:37:19 web.1  |     at Function.app.listen (/Users/craig/Documents/Sandboxes   /xxx/node_modules/express/lib/application.js:535:24)
01:37:19 web.1  |     at Object.<anonymous> (/Users/craig/Documents/Sandboxes/xxx/web.js:25:5)
01:37:19 web.1  |     at Module._compile (module.js:456:26)
01:37:19 web.1  |     at Object.Module._extensions..js (module.js:474:10)
01:37:19 web.1  |     at Module.load (module.js:356:32)
01:37:19 web.1  |     at Function.Module._load (module.js:312:12)
01:37:19 web.1  | exited with code 8
01:37:19 system | sending SIGTERM to all processes
SIGTERM received

谢谢。

--补充信息--

procfile 只有一个条目: 网络:节点 web.js

我已经将监听器设置如下:

var port = process.env.PORT || 5000;
app.listen(port, function() {
    console.log("Listening on " + port);
});

【问题讨论】:

  • 您是否尝试在特定端口上启动您的 HTTP 服务器? (请注意,只要您想在heroku 上启动 HTTP 服务器,就应该使用process.env.PORT 作为端口号)
  • 请发布您的 Procfile 和 node.ks 应用配置
  • 请在原帖中找到上面要求的其他详细信息
  • 我遇到了同样的问题。你有想过这个吗?

标签: node.js heroku foreman


【解决方案1】:

我遇到了同样的问题,Error: listen EADDRINUSE 表示 Node 服务器已经在运行。

检查您没有在本地为同一项目运行节点服务器。如果您正在本地处理与 Heroku 绑定的 GitHub 同步项目(例如在端口 5000 上),则您无法为该项目运行本地节点服务器,因为该端口将被使用两次。

我实际上是在另一个终端窗口中的项目上运行节点服务器,但没有立即注意到。

【讨论】:

    【解决方案2】:

    我刚刚在 OS X 上遇到了这个问题。看起来工头默认选择端口 5000,这似乎与 Bonjour/mDNS/UPNP 服务冲突。 (根据我所读到的内容。我没有花时间找出它是什么。)

    但是,您可以通过两种方式更改工头使用的端口:specify the port on the command linecreate a .foreman file with the port number specified there

    祝你好运,编码愉快!

    【讨论】:

    • 丹尼尔是对的。例如,这对我有用:foreman start -p 8000 所以我最终指定了端口号并且它有效。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2012-08-07
    • 2013-01-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-31
    相关资源
    最近更新 更多