DALL·E 3 generated image of a screen showing errors

How to kill a port that is in use

Apr 20 2024

1 min read

We’ve all seen the dreaded EADDRINUSE error. No worries though, this is super easy to fix.

{
 code: 'EADDRINUSE',
 errno: -48,
 syscall: 'listen',
 address: '::',
 port: 8080
}

There are a few ways to fix this:

tl;dr

‘npx kill-port’ is my goto, it is fast, easy to remember and does what you want it to on both all operating systems.

npx kill-port 8080

But let’s go over all the other available options in case kill port does not work for you.

Unix-based systems (Linux, macOS)

lsof and kill

lsof -ti:8080 | xargs kill

fuser

fuser -k 8080/tcp

netstat and kill

sudo netstat -ltnp | grep ':8080' | awk '{print $7}' | sed 's/\/.\*//' | xargs kill

Windows

netstat and taskkill

netstat -aon | findstr :8080
taskkill /F /PID <PID>

Using PowerShell

Get-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess | Stop-Process -Force

Cross-platform tools

npx kill-port:

As mentioned before, this is a straightforward method that works across different operating systems.

npx kill-port 8080