0

I can start my app using nodemon, just by typing nodemon

but got below error when I do node app.js

enter image description here

My package.json is configured properly. It has

"scripts": { "start": "node ./bin/www" }

Maria Jane
  • 1,963
  • 6
  • 17
  • 34
  • There is a process, maybe a previous execution, that have lock the port number you try to bind. Try to change the port number. – Mario Santini Jul 11 '16 at 14:32

3 Answers3

1

EADDRINUSE means that a port your node application attempted to bind to, has already been bound to by another process. Typically this suggests you haven't killed your last node process before starting the current one, or you haven't configured your application to use the correct port (e.g., a system port that can't be bound to, or a port below 1024 which requires administrative access to bind to).

Patrick Roberts
  • 40,065
  • 5
  • 74
  • 116
0

there is something in use, try to restart your machine and try again. =D

0

The port is already in use, there might be another instance of your application already running. To see what processes are running background use netstat -tlpn and to filter node only processes netstat -tlpn | grep node.

tcp        0      0 127.0.0.1:8081          0.0.0.0:*               LISTEN      22917/node          
tcp        0      0 127.0.0.1:8666          0.0.0.0:*               LISTEN      358/node            
tcp        0      0 127.0.0.1:8667          0.0.0.0:*               LISTEN      4416/node  

As you see the port 8081 is already taken, try to kill it and start you server again kill 22917.

Risto Novik
  • 7,523
  • 8
  • 47
  • 63
  • any idea why I tried to run pm2 start app.js in my express app and it doesn't work? – Maria Jane Jul 11 '16 at 15:00
  • Did you get any error messages, if yes please post here. – Risto Novik Jul 11 '16 at 15:27
  • I made it. I do `pm2 start www/bin` it worked! that's so strange, any idea why? I'm on express 4 – Maria Jane Jul 11 '16 at 15:31
  • If you do use the generator example, the app.js is just another module which does not start the server itself http://expressjs.com/en/starter/generator.html. The http server listen has been moved to `www/bin` in your case https://github.com/expressjs/generator/blob/master/templates/js/www. – Risto Novik Jul 11 '16 at 15:37
  • so express generator and express from scratch is designed differently?! – Maria Jane Jul 12 '16 at 03:50
  • There is no fixed project layout, as it's in express generator the express application has separated into module. This enables the testing easier with `supertest` and `superagent` modules etc. – Risto Novik Jul 12 '16 at 07:44