To kill a dev server
When working with local development servers, a message like this might look familiar:
Error: listen EADDRINUSE: address already in use 127.0.0.1:8888
at Server.setupListenHandle [as _listen2] (net.js:1300:14)
at listenInCluster (net.js:1348:12)
at doListen (net.js:1487:7)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
This doesn’t really give us much information to work with. Since I couldn’t find a solution on the web within a few minutes, this is my contribution for anyone running into the same problem.
The solution
First, we need to find out what process is causing the problem. We will use the lsof -i
command for this. What it does, according to the manual:
selects the listing of files any of whose Internet address matches the address specified to see what application is running on the port
So since the error specifies the application is running on port 8888, we can run:
lsof -i tcp:8888
This outputs:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 11975 user 29u IPv4 0x64ffe67f1d4a089 0t0 TCP localhost:ddi-tcp-1 (LISTEN)
We’ve learned that Node.js is the troublemaker here. Instead of shutting down Node.js entirely, we can just terminate the problematic process by using the PID (11975):
kill -9 11975
Now you should be able to run your development server without any problems.