port 4200 is already in use

“Port 4200 is already in use” while running ng serve Angular CLI command

When you tried to run an Angular Project using “ng serve” command and see error like “Port 4200 is already in use. Use ‘–port’ to specify a different port“.

Solution

First you can investigate whether the port 4200 is already in use. To check that try running the following netstat command in Windows

> netstat -a -n -o | findstr :4200
  TCP    127.0.0.1:4200         0.0.0.0:0              LISTENING       18028
  TCP    127.0.0.1:4200         127.0.0.1:61741        ESTABLISHED     18028
  TCP    127.0.0.1:61741        127.0.0.1:4200         ESTABLISHED     4344

The PID “4344” is from “ng serve”. If you would like to kill this process, then run the following command.

> taskkill /PID 4344 /F
SUCCESS: The process with PID 4344 has been terminated.

If you don’t like to terminate the process and wanted to specify a different port, then you can run the following command

> ng serve --port 8001

This means that you already have another service running on port 4200 and you can either terminate the process or service which is using that port or use the flag “–port” while runnning “ng serve”

The above command would change the URL to something like

http://localhost:8001

Hope this resolves this issue 🙂

Further Learning

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments