angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Port 4200 is already in use

Open mInzamamMalik opened this issue 9 years ago • 25 comments

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

mInzamamMalik avatar Jan 24 '17 13:01 mInzamamMalik

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

danielsogl avatar Jan 24 '17 13:01 danielsogl

@MTechDE i know but why not automatically, just like ionic-cli does kindly let me know if there is any good reason behind this

mInzamamMalik avatar Jan 24 '17 13:01 mInzamamMalik

They have to implement something like this: https://www.npmjs.com/package/ember-cli-auto-port Angular-CLI is based on the Ember CLI

danielsogl avatar Jan 24 '17 13:01 danielsogl

I would view the current deterministic behavior as an important trait of a development tool. Scripted and test-related scenarios, for example, rely on a particular setup. And if something is running on a port that is expected to be free, something is wrong.

clydin avatar Jan 24 '17 13:01 clydin

Dupe of https://github.com/angular/angular-cli/issues/1568

filipesilva avatar Jan 24 '17 17:01 filipesilva

lsof -t -i tcp:80 -s tcp:listen | sudo xargs kill

ashfaq22iit avatar Jul 31 '17 18:07 ashfaq22iit

ng serve --port 4201

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

mcakar1993 avatar Aug 02 '17 06:08 mcakar1993

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

melhaer avatar Oct 06 '17 13:10 melhaer

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

kaustubhtalathi avatar Oct 21 '17 02:10 kaustubhtalathi

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.

harmeshg5 avatar Jan 04 '18 06:01 harmeshg5

capture

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

melhaer avatar Jan 04 '18 08:01 melhaer

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.

enesyurtlu avatar Mar 16 '18 20:03 enesyurtlu

Port 4200 is already in use. Use '--port' to specify a different port This means that you already have another service running on port 4200. If this is the case you can either . shut down the other service or. use the --port flag when running ng serve like this: ng serve --port 9001 Another thing to notice is that, on some machines, the domain localhost may not work. You may see a set of numbers such as 127.0.0.1. When you run ng serve it should show you what URL the server is running on, so be sure to read the messages on your machine to find your exact development URL.

daliri72 avatar Apr 22 '18 10:04 daliri72

I'm a few weeks in with Angular and Visual Studio Code and it was working quite well, but now when I terminate the batch job it goes back to the cli, but then when I try to restart my app it gives the port error. I then have to track it down using netstat and kill it directly.

I know I can specify a new port, buy can anyone give me an idea of why my app is not releasing the port?

goneos avatar May 01 '18 23:05 goneos

https://stackoverflow.com/a/48476963/5812106 I usually use the ng set command to change the Angular CLI settings for project level.

ng set defaults.serve.port=4201 It changes change your .angular.cli.json and adds the port settings as it mentioned earlier.

After this change you can use simply ng serve and it going to use the prefered port without the need of specifying it every time.

agiletuan avatar May 07 '18 03:05 agiletuan

PS D:\Algomonk\practice\angular7app> ng serve --port 4201 ** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **

kishan8400 avatar Nov 25 '18 04:11 kishan8400

why should i keep 4200 listening and resort to another port?! it is a good practice not to have anything unnecessarily works on your machine, so kill it!

ahmedohadi avatar Nov 26 '18 05:11 ahmedohadi

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

Qasmi2 avatar Mar 01 '19 07:03 Qasmi2

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

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

Dx avatar Mar 06 '19 04:03 Dx

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

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

netstat -ano | findstr 4200 taskkill /F /PID 16876

konidala avatar Mar 14 '19 14:03 konidala