Port 4200 Is Already In Use. Use ‘–Port’ To Specify A Different Port Error
Port 4200 is already in use. Use ‘-port’ to specify a different port error
occures sometimes when we run our angular app using ng serve
That means there is another existing service already running on port 4200.
Port 4200 is already in use.Use ‘-port’ to specify a different port error Reasons
- An existing application(not angular) in your system using the port number 4200. This is a very rare scenario. In this case, you need to change the port number of angular application as mentioned below.
- You already ran
ng serve
and to exit the application you typed Control Z (Ctrl+Z), And then you typedng serve
then you will getport 4200 is already in use_ error
. In this case, you need to kill the previous process
To close or terminate the angular instance always use Control+C (Ctrl+c)
And 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.
According to RFC 793 port numbers is a 16-bit unassigned integer. The minimum value is 0 and the maximum value is 65535.
And, within this range, ports 0 – 1023 are reserved for specific purposes(mostly).
To change the port number for our angular application use the below command
ng serve --port 4201
Now type ng serve
Our angular application will be running on http://localhost:4201
To kill already existing angular process use the below commands
Fix Port 4200 is already in use.Use ‘-port’ to specify a different port error in Mac & 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 Port 4200 is already in use.Use ‘-port’ to specify a different port error in Window
In Window operating system open command prompt. Use the following command to fix port 4200 is already in use error.
netstat -a -n -o | findStr "4200"`
Take the process id and kill the process using the following command
taskkill -f /pid 11128