1

When trying to run ng serve I get the following error:

Port 4200 is already in use. Use '--port' to specify a different port.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! product@0.0.0 start: `ng serve --host 0.0.0.0 --disable-host-check`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the product@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Mohammad Ajo\AppData\Roaming\npm-cache\_logs\2019-08-18T18_19_41_366Z-debug.log

I've checked the port if it's reserved by another connection or not and tried to change the port multiple times with not and keep getting the same error.

Sangwin Gawande
  • 6,028
  • 8
  • 40
  • 58
Mohammad Ajo
  • 41
  • 1
  • 5
  • 3
    close vscode and reopen it, 10$ you're running more than one terminal – Stavm Aug 18 '19 at 18:28
  • 2
    `lsof -i :4200` to find it and kill it ( Liam Neeson style ) – Federkun Aug 18 '19 at 18:32
  • I'm using intelliJ on Windows 10. The error still appears even after restarting my computer. – Mohammad Ajo Aug 18 '19 at 18:36
  • Go to resource montior(you can search it in start menu), and open the `network` tab, and check which process is using the 4200 port and `end process` it. https://stackoverflow.com/questions/48198/how-can-you-find-out-which-process-is-listening-on-a-port-on-windows – Aritra Chakraborty Aug 18 '19 at 18:47

5 Answers5

1

I was facing the same issue just a couple of hours ago. Try checking out: https://github.com/angular/angular-cli/issues/15369

Installing portfinder@1.0.21 worked in my case.

iNano
  • 28
  • 3
1

to connect asp.net web api project with angular I have given port 4200 to it.If you just not did like that you can use ng serve --port 4600 like another port it works for me.

pamal Sahan
  • 131
  • 1
  • 4
1

For Linux users:- this one is working for me

kill -9 $(lsof -t -i:4200)
hazan kazim
  • 670
  • 6
  • 9
0

Try running ng serve --port 4500 or change package.json and instead of

"start": "ng serve",

type

"start": "ng serve --port 4500",

and then run npm start command

Dmitry Samoylov
  • 838
  • 1
  • 9
  • 23
0

Run following command, ---o will open new window automatically with different port :

ng serve ---o --port=0 // will open on random port automatically

If you want specific port then run :

ng serve ---o --port 4201 // Will open on port 4201
Sangwin Gawande
  • 6,028
  • 8
  • 40
  • 58