Port used to launch Node.js application with Heroku Foreman

I am trying to deploy my node.js application for heroku, but when I try to run it locally using the wizard, I get Error: listen EADDRINUSE. I run netstat and grepped for the port, nothing uses it anymore, and the server starts without problems when starting directly as a node http server.

The application I'm trying to deploy uses mongo and redis. I'm not sure if these components will affect the server starting with Foreman. Does anyone have suggestions on areas that I could look at for possible errors?

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 -

There is only one entry in the procfile: web: node web.js

and I set the listener as follows:

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

I just ran into this on OS X. It seems that the wizard chooses port 5000 by default, which seems to run counter to Bonjour / mDNS / UPNP services. (From what I read, I did not find the time to choose what it is.)

However, you can change the port that the wizard uses in two ways: either specify a port on the command line or create a .foreman file with the port number specified there .

Good luck and happy coding!

+7
source

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

Make sure you are not using a Node server for a local project. If you are working on a local GitHub project locally (for example, on port 5000) that is bound to Heroku, you cannot start the local Node server for this project, since the port will be used twice.

I actually started the Node server in the project in a different terminal window and did not immediately notice.

+2
source

Source: https://habr.com/ru/post/954621/


All Articles