“Port 4200 is Already in Use” When Running the ng serve Command

In this post, I show you how to fix "port 4200 is already in use" issue occurs sometimes when we run our angular app using ng serve.
This means there is another existing service already running on port 4200.
As we know, the ng serve uses default port number 4200 to run the angular application. And our application URL will be http://localhost:4200. To avoid this error we need to change the port number to other port which is free.
To change the port number for our angular application use the below command
ng serve --port 4201
Our angular application will be running on http://localhost:4201
To kill already existing angular process use the below commands.

Fix for Mac and Linux

To fix port 4200 is already in use error in In Mac & Linux OS (Ubuntu etc) use the following commands
sudo kill $(sudo lsof -t -i:4200) Or
sudo kill `sudo lsof -t -i:4200` Or
sudo lsof -t -i tcp:4200 | xargs kill -9

Fix for Window

Type below command in cmd:
netstat -a -n -o
And then, find the 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 4476.
Take the process id and kill the process using the following command:
taskkill -f /pid 4476
Below screenshot for your reference: 

Comments