Fastest Method (Any OS)
$ npx portrm fix 3000
That is it. Works on macOS, Linux, and Windows. No PID lookup, no platform-specific commands.
If you want to kill and restart your dev server:
$ npx portrm fix 3000 --run "npm run dev"
macOS
Method 1: lsof + kill
# Find the PID
$ lsof -ti :3000
84921
# Kill it
$ kill -9 84921
Method 2: One-liner
$ lsof -ti :3000 | xargs kill -9
Method 3: Using fuser
$ fuser -k 3000/tcp
Warning:
kill -9 sends SIGKILL, which does not allow the process to clean up. Use kill (SIGTERM) first for a graceful shutdown. portrm handles this automatically.
Linux
Method 1: fuser
$ fuser -k 3000/tcp
Method 2: ss + kill
$ ss -tlnp | grep :3000
LISTEN 0 511 *:3000 *:* users:(("node",pid=84921,fd=23))
$ kill 84921
Method 3: lsof (if installed)
$ lsof -ti :3000 | xargs kill
Windows
Method 1: Command Prompt
# Find the PID
> netstat -ano | findstr :3000
TCP 0.0.0.0:3000 0.0.0.0:0 LISTENING 12345
# Kill it
> taskkill /PID 12345 /F
Method 2: PowerShell
PS> Get-NetTCPConnection -LocalPort 3000 | Select-Object OwningProcess
PS> Stop-Process -Id 12345 -Force
Method 3: PowerShell One-liner
PS> Get-NetTCPConnection -LocalPort 3000 | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }
What Commonly Uses Port 3000?
| Service | Default Port | Fix Command |
|---|---|---|
| React (Create React App) | 3000 | ptrm fix 3000 |
| Next.js | 3000 | ptrm fix 3000 |
| Express.js | 3000 | ptrm fix 3000 |
| Rails | 3000 | ptrm fix 3000 |
| Grafana | 3000 | ptrm fix 3000 |
| NestJS | 3000 | ptrm fix 3000 |
Automate It in Your Project
Add a pre-script to your package.json so port 3000 is always cleared before starting:
{
"scripts": {
"predev": "npx portrm fix 3000 -y",
"dev": "next dev"
}
}
Now npm run dev always works on the first try.
Never look up PIDs again
One command. Any port. Any OS.