When developing you will inevitably try to start a new process only to find that the port is already in use.
You have a few options on how to resolve this issue.
Option 1: Use the npm kill-port package
This npm package is used to target and kill the process on a given port. (You can find the package here)
Option 2: Kill the process that is using the port (Windows)
When killing the process in Windows – use a PowerShell or Command Line terminal (this will not work in Git Bash).
There are 2 steps to killing the process.
- Find the process id (PID) of the process that is using the port
- Kill the process
Step 1
Use the netstat utility to find the process id:
netstat -ano | findstr :<your port>
or
netstat -a -n -o | findstr :<your port>
If port 3000 is blocked I find the process by executing:
I find that the PID is 50060
Netstat documentation can be found here for Windows and Linux.
Step 2
Kill the port by using the taskkill command
taskkill /pid 50060 /f
allows you to specify the process to kill
/pid
/f
specifies that you want to force the termination
Option 3: net stop / net start
Options 3 and 4 involve restarting the host network service. This will shut down all network services and only restart the ones that are configured to run automatically.
The net stop winnat
and net start winnat
commands can be run from PowerShell, Git Bash or Command Line but you need to run the terminal as administrator.
Option 4: Restart the Host Network Service
Open the services window, locate Host Network Service, and restart the service.
Leave a Reply