使用Heroku Foreman启动Node.js应用程序时使用的端口

我正在尝试将我的node.js应用程序部署到heroku,但是当我尝试使用工头在本地启动它时,我得到Error:listen EADDRINUSE。 我已经运行一个netstat和grepped的端口没有别的使用它和服务器直接作为节点http服务器运行时启动没有问题。

我试图部署的应用程序是使用mongo和redis我不确定这些组件是否会影响Foreman开始的服务器。 有没有人有任何build议,我可以看看潜在的错误?

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); }); 

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

但是,您可以通过两种方式更改工头所使用的端口:在命令行上指定端口或使用在那里指定的端口号创build.foreman文件 。

祝你好运,快乐的编码!

我有同样的问题, Error: listen EADDRINUSE意味着一个节点服务器已经运行。

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

我实际上是在一个不同的terminal窗口中的项目上运行一个节点服务器,并没有立即注意到。