6

我正在尝试将我的 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: node web.js

我已将侦听器设置如下:

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

2 回答 2

7

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

但是,您可以通过两种方式更改工头使用的端口:在命令行上指定端口创建一个 .foreman 文件,其中指定的端口号

祝你好运,编码愉快!

于 2013-12-19T14:48:22.163 回答
2

I had the same issue, Error: listen EADDRINUSE means that a Node server is already running.

Check that you are not running a Node server for the same project locally. If you are working on a GitHub synced project locally (on port 5000 for instance) which is tied to Heroku you cannot run a local Node server for that project as the port will be in use twice.

I was actually running a Node server on a project in a different Terminal window and didn't notice immediately.

于 2014-07-25T10:34:51.750 回答