
How to Kill a Running Port in PowerShell (Fix Port 3001 Issue in VS Code)
Sometimes when you stop your app in VS Code, the process doesn’t fully terminate. As a result, your app keeps running on port 3001, even when you want to use port 3000.
Sometimes when you stop your app in VS Code, the process doesn’t fully terminate.
As a result, your app keeps running on port 3001, even when you want to use port 3000.
This is common with:
- Next.js
- Node.js
- Express
- Payload CMS
This guide shows how to safely kill the running process using PowerShell.
🚨 The Problem
You try to start your app:
npm run dev
But you see something like:
Port 3000 is already in use, trying 3001...
Even after closing VS Code or stopping the terminal, port 3000 is still occupied.
✅ Solution: Kill the Process Using PowerShell
Step 1: Find the process using port 3000
Open PowerShell (Run as Administrator is recommended):
netstat -ano | findstr :3000
Example output:
TCP 127.0.0.1:3000 0.0.0.0:0 LISTENING 12345
👉 The last number (12345) is the PID (Process ID).
Step 2: Kill the process by PID
Run:
taskkill /PID 12345 /F
If successful, you’ll see:
SUCCESS: The process with PID 12345 has been terminated.
Step 3: Restart your app
Now go back to your project and run:
npm run dev
Your app should now run correctly on:
http://localhost:3000
⚡ One-Line Shortcut (Advanced)
If you want a faster way, you can kill whatever is using port 3000 in one command:
Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess | Stop-Process -Force
⚠️ Use this carefully — it immediately stops the process.
🧠 Why This Happens
This usually occurs when:
- VS Code crashes
- Node process hangs
- Hot reload doesn’t exit cleanly
- A previous dev server is still running in the background
✅ Best Practices to Avoid This Issue
- Always stop the server with
Ctrl + C - Close unused terminals
- Restart VS Code if ports behave strangely
- Use a
.envfile to explicitly define your port: PORT=3000
Final Tip
This trick works not just for 3000, but any port:
- 3001
- 4000
- 8000
- 5432 (Postgres)
Just replace the port number.
