[Solved] "Port 4200 is already in use" when running the ng serve command - Angular
Problem:
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.
Solution:
For Windows Users:At first, we have to check which port are running on system.
Step 1: Open your CMD as Administrator mode.
Step 2: Then find the PID of port 4200 with this command -
netstat -ano | findstr :4200
Then you can show like this -
- Red one is from "ng-serve" (127.0.0.1:4200) that LISTENING
Now we kill only port 4200
taskkill /PID 15940 /F
Now you can see – SUCCESS: The process will PID 15904 has terminated.
For Mac OS Users:sudo lsof -t -i tcp:4200 | xargs kill -9
Note: Remember you need to kill Angular's web server with Command+C
For Linux users:sudo kill $(sudo lsof -t -i:4200)
you can also use -
sudo kill `sudo lsof -t -i:4200`