angular-cli: Port 4200 is already in use

it should automatic shift on other port if a port is busy, currently when i try to serve two projects at a time i always get error:

Port 4200 is already in use

Thank You, M.Inzamam Malik

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (4 by maintainers)

Most upvoted comments

For Windows:

Open Command Prompt and type: netstat -a -o -n Find the PID of the process that you want to kill. Type: taskkill /F /PID 16876 This one 16876 - is the PID for the process that I want to kill - in that case, the process is 4200 - check the attached file.

capture

You can set your port with ng serve --port 1234

Ubuntu ( terminal command ) kill -9 $(lsof -i tcp:4200 -t)

For Windows this worked for me: ## taskkill -F -PID 16876

capture

For Windows you can also kill the process (Node.js) through the Task Manager - this is the easiest way to do it:)

You can also try with this to run your application in visual studio code -:

ng serve --open --port 4201

you can give any port number.

the command @Qasmi2 suggested, works on Mac OSX too 👍

kill -9 $(lsof -i tcp:4200 -t)

I also faced this problem suddenly and solved it by deleting node_modules folder and package-lock.json and again doing npm install.

something changed in package-lock.json caused this problem to me

lsof -t -i tcp:80 -s tcp:listen | sudo xargs kill this works ! But I want it in angular-cli. If specified port is in use, cli can automatically stop that.

ng serve --port 4201

default port 4200 so already another project work in same port. So change it as 4201 or any other

I also faced this problem suddenly and solved it by deleting node_modules folder and package-lock.json and again doing npm install.

something changed in package-lock.json caused this problem to me

Yes, Finally it works. Thank you for your solution. I wasted two days on it.