简体   繁体   English

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

[英]Port in use when launching Node.js app with Heroku Foreman

I am trying to deploy my node.js app to heroku but when I try to launch it locally using foreman I am getting Error: listen EADDRINUSE. 我正在尝试将我的node.js应用程序部署到heroku但是当我尝试使用foreman在本地启动时,我收到错误:听EADDRINUSE。 I have run a netstat and grepped for the port nothing else is using it and the server starts without issue when running directly as a node http server. 我已经运行了一个netstat并且为端口进行了grepped,没有其他人正在使用它,并且当直接作为节点http服务器运行时,服务器启动时没有问题。

The app I am trying to deploy is using mongo and redis I am not sure if these components will effect the server starting with Foreman. 我试图部署的应用程序是使用mongo和redis我不确定这些组件是否会影响从Foreman开始的服务器。 Does anyone have any suggestions on areas I could look at for potential bugs? 有没有人对我可以查看潜在错误的方面有任何建议?

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

Thanks. 谢谢。

--Additional information-- - 附加信息 -

The procfile just has one entry: web: node web.js proc文件只有一个条目:web:node web.js

and I have set the listener up as follows: 我已经将监听器设置如下:

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

I just ran into this on OS X. It looks like foreman picks port 5000 by default, which seems to conflict with Bonjour/mDNS/UPNP services. 我刚刚在OS X上碰到了这个。看起来工头默认选择端口5000,这似乎与Bonjour / mDNS / UPNP服务冲突。 (From what I've read. I haven't taken the time to pick out which it is.) (据我所读。我没有花时间去挑选它。)

However, you can change the port that foreman uses in two ways: specify the port on the command line or create a .foreman file with the port number specified there . 但是,您可以通过两种方式更改foreman使用的端口:在命令行上指定端口使用此处指定的端口号创建.foreman文件

Good luck and happy coding! 祝你好运,编码愉快!

I had the same issue, Error: listen EADDRINUSE means that a Node server is already running. 我遇到了同样的问题, Error: listen EADDRINUSE意味着节点服务器已在运行。

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. 如果您正在本地(在端口5000上)处理与Heroku绑定的GitHub同步项目,则无法为该项目运行本地节点服务器,因为该端口将被使用两次。

I was actually running a Node server on a project in a different Terminal window and didn't notice immediately. 我实际上是在不同的终端窗口中的项目上运行节点服务器,并没有立即注意到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM