• Register
0 votes
131 views

Problem :

Currently I am trying to learning angular 2 and angular CLI also I am using the angular CLI and angular 2 for a very first time to create the sandbox project.

I ran the following command "ng serve" and it worked for me. After that I wanted to stop the command so I pressed the "Control Z".

But now if I try to run the "ng-serve" command again then it gives me below error:

"Port 4200 is already in use. use '--port' to specify a different port."

I am trying to fix this error from past couple of days but unable to fix it. Can somebody help me in fixing it ?
2.3k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I had also faced the error related to port 4200 recently. I followed below ways to kill the progress on the port number 4200

If you are using Linux :

Then use the below command to fix it

sudo kill $(sudo lsof -t -i:4200)

You could also try below command:

sudo kill `sudo lsof -t -i:4200`

If you are using Windows :

Then you need to open your cmd as administrator and type below command in your cmd:

netstat -a -n -o

After that you need to find the port with port number 4200 by just right clicking on your terminal and then click on find, enter the 4200 in your "find what" and then click on the "find next": If you found that the port number 4200 is used by the pid 18932. Then you need to type below command in cmd:

taskkill -f /pid 18932
5k points
0 votes

Solution:

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

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.

Step 1: Find the connection’s PID

> netstat -ano | findstr :yourPortNumber

Step 2: Kill the process using it’s PID

> tskill yourPID

Step 3: Restart your server

You should be able to run it (using ng serve)
 

Step 4: Stop your server properly

Don’t forget now to close properly your server by using Ctrl + C and typing Y:
31.7k points