15

I was wondering if it is possible to work on two Angular(2) projects at the same time. I open my first project using ng serve and it runs on the server and when I save it it updates. But of coarse when I try to open another project with ng serve it will tell you that "port:4200 is already in use". Is there a way to open a project on a different port?

Seeing that this is a virtual server, I can not think that just giving it another port number can be to difficult. I do not want to log out of the one project the whole time, and then into the second one and back again after changing just one line to see if it works.

Regards

Alfa Bravo
  • 1,961
  • 2
  • 25
  • 45

3 Answers3

37

Open 2nd project then run this command:

ng serve --port 4210

Change port as you want, then open browser: localhost:[port]

Following this section:

https://github.com/angular/angular-cli#generating-and-serving-an-angular-project-via-a-development-server

Steve Schrab
  • 375
  • 5
  • 15
Tiep Phan
  • 12,386
  • 3
  • 38
  • 41
  • Hi Tiep, do I run this for the second project after running `ng serve` normally for the first project? And then just open localhost:4210 in browser for second project? Are the port numbers specific or can I use any numbers, just for clarity? – Alfa Bravo Feb 09 '17 at 15:57
  • Ah ok, got the answers from the links... Thanks allot!! – Alfa Bravo Feb 09 '17 at 15:59
  • use any unuse port: > 1024, because almost port from 1 -1024 are use by some service: 80 -> http. 443 -> https, 21 -> ssh, ... angular cli by default using port 4200 – Tiep Phan Feb 09 '17 at 16:01
  • That works fine. Thanks. Better find open ports first and assign it. – Anoj Jan 06 '22 at 14:51
6

If you're using angular-cli, It is pretty easy :

In console run :

ng serve --host 0.0.0.0 --port 4201 --live-reload-port 4915

For reference : https://github.com/angular/angular-cli

v8-E
  • 1,077
  • 2
  • 14
  • 21
Pezetter
  • 2,783
  • 2
  • 22
  • 40
1

Open Seconde terminal in vsCode

ng serve --port 4210

Change port number as you want, then open browser: localhost:[port]

Sushil
  • 670
  • 7
  • 14