Releasing blocked ports on your dev machine

When developing you will inevitably try to start a new process only to find that the port is already in use.

The port is 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.

  1. Find the process id (PID) of the process that is using the port
  2. 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
/pid
allows you to specify the process to kill
/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.

Restart the Host Network Service



Categories: Misc, Web

Tags: ,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: