How to Free Up a Port on Windows
If you've ever tried to start a local server and been greeted with an error like "port already in use," you're not alone. It usually means another process is still holding onto that port — often a leftover dev server that didn't shut down properly. Here's a quick, reliable way to find and kill it using the Windows command line.
Step 1: Find the Process Using the Port
Open Command Prompt (cmd.exe). You may need to run it as an administrator, though this isn't always required.
Run the following command, replacing <Port Number> with the port you're trying to free up:
netstat -ano | findstr <Port Number>
This lists any active connections on that port, along with a PID (Process ID) — the number you'll need in the next step.
Example
Let's say something is hogging port 18080:
netstat -ano | findstr 8080
TCP 0.0.0.0:18080 0.0.0.0:0 LISTENING 19788
TCP [::]:18080 [::]:0 LISTENING 19788
Here, the PID is 19788.
Step 2: Kill the Process
Now use taskkill to terminate that process:
taskkill /F /PID <Process Id>
Following the example above:
taskkill /F /PID 19788
SUCCESS: The process with PID 19788 has been terminated.
And that's it — the port is now free to use again.
A Quick Word of Caution
Before killing a process, double-check what it actually is, especially if you're working on a shared machine or aren't sure what's running. Killing the wrong process can close unsaved work or disrupt something you didn't mean to touch.
Source: CodeGrepper
Top comments (1)
There's no area circled in red.