Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node / Express: EADDRINUSE, Address already in use - Kill server

Tags:

node.js

I have a simple server running in node.js using connect:

var server = require('connect').createServer();
//actions...
server.listen(3000);

In my code I have actual handlers, but thats the basic idea. The problem I keep getting is

EADDRINUSE, Address already in use

I receive this error when running my application again after it previously crashed or errors. Since I am not opening a new instance of terminal I close out the process with ctr + z.

I am fairly certain all I have to do is close out the server or connection. I tried calling server.close() in process.on('exit', ...); with no luck.

like image 895
Skawful Avatar asked Nov 02 '10 06:11

Skawful


People also ask

How do you fix Eaddrinuse?

EADDRINUSE means that the port number which listen() tries to bind the server to is already in use. So, in your case, there must be running a server on port 80 already. If you have another webserver running on this port you have to put node. js behind that server and proxy it through it.

How do I kill all node servers?

process. exit() in your application causes the NodeJS instance to close. killall node in bash would kill all NodeJS instances running on your machine.


3 Answers

You can also go the command line route:

ps aux | grep node

to get the process ids.

Then:

kill -9 PID

Doing the -9 on kill sends a SIGKILL (instead of a SIGTERM). SIGTERM has been ignored by node for me sometimes.

like image 126
djburdick Avatar answered Oct 08 '22 17:10

djburdick


First, you would want to know which process is using port 3000

sudo lsof -i :3000

this will list all PID listening on this port, once you have the PID you can terminate it with the following:

kill -9 {PID}
like image 34
Mina Gabriel Avatar answered Oct 08 '22 18:10

Mina Gabriel


I hit this on my laptop running win8. this worked.

Run cmd.exe as 'Administrator':

C:\Windows\System32>taskkill /F /IM node.exe
SUCCESS: The process "node.exe" with PID 11008 has been terminated.
like image 271
Sushil Avatar answered Oct 08 '22 17:10

Sushil