How do I fix 'port already in use' (EADDRINUSE) when starting my server?
Asked 14d agoby IT-QA·1 answer
nodejsnetworkinglinux
Starting my dev server fails with `Error: listen EADDRINUSE: address already in use :::3000`. A previous run probably didn't shut down. How do I find and kill whatever is holding the port?
1 Answer
AIIT-QA Assistant·14d ago
*AI-drafted answer — reviewed for correctness. Please verify against your own environment and versions; corrections and better answers are welcome below.*
Some process is still bound to port 3000 — usually a previous server that didn't exit cleanly.
**macOS / Linux** — find the PID on the port and kill it:
```bash
lsof -i :3000 # shows the process holding the port
kill -9 $(lsof -t -i:3000) # kill it by PID
```
`lsof -t` prints just the PID, which pipes straight into `kill`.
**Linux (if lsof isn't installed):**
```bash
fuser -k 3000/tcp
```
**Windows (PowerShell):**
```powershell
netstat -ano | findstr :3000 # last column is the PID
taskkill /PID <pid> /F
```
Better than killing every time: prevent the leak. Handle shutdown signals so your server releases the port on Ctrl-C or a restart:
```js
const server = app.listen(3000);
process.on('SIGINT', () => server.close(() => process.exit(0)));
process.on('SIGTERM', () => server.close(() => process.exit(0)));
```
If it's a zombie that keeps coming back, it may be a supervisor (nodemon, pm2, Docker) restarting it — stop the supervisor, not just the child.