Let´s say we have this warning “Port 4200 is already in use” when running the ng serve command“.

And all the (IDE) terminal are closed.

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

Windows User ( Alternative 2)

Open your cmd.exe as administrator,

then Find the PID of port 4200

netstat -ano | findstr :4200
https://i.stack.imgur.com/mOSAv.png

Here I have 3 PID :

  • Red one is from “ng-serve” (127.0.0.1:4200) that LISTENING
  • Green one is from “your browser”

kill only port 4200 (kill the red PID):

taskkill /PID 15940 /F
https://i.stack.imgur.com/ATfte.png

note : kill the green one will only lead your browser closed by force.

now you can do “ng-serve” to start your angular app at the same port 4200

For UNIX:

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.

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *