Node js listens for EADDRINUSE error for simple httpserver

I have a simple node js http server.

var http = require("http"); http.createServer(function(request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.write("Hello World"); response.end(); }).listen(8888); 

If I run

 node basicserver.js 

I get

 node.js:201 throw e; // process.nextTick error, or 'error' event on first tick ^ Error: listen EADDRINUSE at errnoException (net.js:642:11) at Array.0 (net.js:743:26) at EventEmitter._tickCallback (node.js:192:40) 

I saw this post, but this message seems to be specific to the TCP server, not the http server. Can anyone help.

+10
source share
7 answers

The port you are listening to is already being tapped by another process. In this case, I got the feeling that this is yours. Can you make ps aux | grep node ps aux | grep node , and then use kill <pid> kill your node process. Alternatively, you can also try a different port.

- Update -

If you want to find which process is listening, you can use netstat -lpn ( -l to find out the listening ports, -p to include the process name and pid, -n not to allow host names, otherwise it will be slow) to find processes that are tapped on different ports. If there were too many, you can do netstat -lnp | grep :8888 netstat -lnp | grep :8888 .

You can also use fuser 8888/tcp , which will show you the pid process, and adding -k will kill the process, the fastest way ever.

I realized that these two commands only work on Linux .

+25
source

To kill all the experiments on my car ...

  killall node 
+6
source

The port you are listening to is already being tapped by another process.

When I ran into this error, I killed the process using Windows PowerShell (because I used Windows)

  1. open Windows PowerShell
  2. print ps and then you can get a list of processes
  3. find the process named node and pay attention to Id
  4. type Stop-process <Id>

I think this is help for Windows users.

+3
source

The same problem may occur when you try to start the server, but you do not have root privileges.

+2
source

I also ran into this problem with EADDRINUSE 127.0.0.1. After checking Node processes, I changed the IP address of the server to "localhost". After that, it all started. Hope this helps.

0
source

On my Linux Mint , only PID kill works:

netstat -nltp | grep 8080 netstat -nltp | grep 8080 netstat -nltp | grep 8080 netstat -nltp | grep 8080 - shows the PID port 8080 , my output is:

tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 27599/node - The PID the dev server in my case is 27599

and then kill

kill -9 <PID>

kill -9 27599

Preamble:

I don’t know what the error is, but I start my WebPack server like npm run dev :

webpack-dev-server --hot --host int.loc --port 8080

And when it is interrupted - in the terminal using Ctrl+C and run it again - it causes the same Error: listen EADDRINUSE 127.0.0.1:8080 , but all the time until it worked perfectly.

killall node did not help.

0
source

For Windows users: in Powershell you can use:

 Stop-Process -Name "ProcessName" -Force 

In this case, "ProcessName" will be "node" .

More info here: How to kill a process on Windows

0
source

All Articles