[Fixed] "Port 4200 is already in use" when running the ng serve command


I am learning angular 2 and for the first time I am using the angular CLI project to create a sandbox project.

I was able to run the command “ng serve” and it works great. I wanted to stop it from running so I ran “Control Z”.

When I tried to run the “ng-serve” command again it gives me “Port 4200 is already in use.”

I ran “PS” to get a list of the PID and killed the PID for the angular-cli and ran “ng-serve” again still it gives the same port in use error.


This is what I used to kill the progress on port 4200

For linux users:

sudo kill $(sudo lsof -t -i:4200)

You could also try this:

sudo kill `sudo lsof -t -i:4200`

For windows users:

Port number 4200 is already in use. Open the cmd as administrator. Type below command in cmd:

netstat -a -n -o

And then, find port with port number 4200 by right click on terminal and click find, enter 4200 in “find what” and click “find next”:
Let say you found that port number 4200 is used by pid 18932. Type below command in cmd:

taskkill -f /pid 18932


alias ngf='kill -9  $(lsof -t -i:4200);ng serve'

Now run ngf (instead of ng serve) in terminal from the project folder. This will kill all processes using the port 4200 and runs your Angular project.

Leave a Reply

(*) Required, Your email will not be published