How to kill a port

How to Kill a Process That Is Using a Specific Port on Windows
Have you ever tried to start your development server and received an error like this?
Error: Port 3001 is already in use
Even after closing VS Code, your terminal, or the project folder, the port may still be occupied by a background process.
Here's a quick way to find and terminate the process.
Step 1: Find the Process Using the Port
Open Command Prompt as Administrator and run:
netstat -ano | findstr :3001
Replace 3001 with the port you're trying to free.
Example output:
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING 21796
TCP [::]:3001 [::]:0 LISTENING 21796
The last number (21796) is the Process ID (PID).
Step 2: Kill the Process
Run:
taskkill /PID 21796 /F
If successful, you'll see:
SUCCESS: The process with PID 21796 has been terminated.
Step 3: Verify the Port Is Free
Run the command again:
netstat -ano | findstr :3001
If nothing is returned, the port has been released and you can start your development server again.
Notes
-
If you receive:
ERROR: The process "1234" not found.it simply means that process has already ended or the PID is incorrect.
-
Always run
netstatagain to get the latest PID before usingtaskkill, since PIDs change whenever processes restart.
Example
C:\Windows\System32>netstat -ano | findstr :3001
TCP 0.0.0.0:3001 0.0.0.0:0 LISTENING 21796
C:\Windows\System32>taskkill /PID 21796 /F
SUCCESS: The process with PID 21796 has been terminated.
That's it! Your port is now free, and you should be able to restart your Next.js, React, Node.js, Express, or any other development server without the "port already in use" error.
Have a project in mind?
I'm currently available for freelance projects and technical consulting.
Get in Touch