0

When I start ng serve server on the command line it fails with:

Starting inspector on localhost:7777 failed: address already in use

This is expected, because there is really already another instance running.

So how can I change the inspector port for this instance?

I've tried to set the env-var NODE_OPTIONS to

  • '--inspect=7888'
  • '--inspect=localhost:7888'

both had no effect: i.e. it was still failing with

Starting inspector on localhost:7777 failed: address already in use

Note: I do NOT want to change the application port: e.g. ng serve --port 5600 - it's only about the node-inspector port

TmTron
  • 17,012
  • 10
  • 94
  • 142
  • Possible duplicate https://stackoverflow.com/questions/37154813/angular-cli-server-how-to-specify-default-port ? – Oriol_IL Oct 24 '19 at 07:51
  • @Oriol_IL no, that would change the port that the application will listen on - not the inspector port – TmTron Oct 24 '19 at 07:57
  • 1
    Think inspector is backend related, not Angular therefore doesn't have anything with ng serve command – mxr7350 Oct 24 '19 at 08:01

2 Answers2

4

tldr;

Since ng serve server uses nrwl/node:execute I must use the nrwl port option:

ng serve server --port 7888

and not the ng serve port:

ng serve  --port 7888 server

Details:

When I start ng serve server, then ng will

  • check the angular.json file for the project server
  • in this project the architect-serve section is relevant

in my case, this is

"serve": {
  "builder": "@nrwl/node:execute",
  "options": {
    "buildTarget": "server:build"
  }
}

Thus, ng will just start the @nrwl/node:execute bulder, which supports the option -port

So to summarize, there are 2 port options available

ng serve -port 5600 server -port 7888
  • 5600 is the application port (which I need not chagne in this case)
  • 7888 is the inspector port, which I must change in this case
TmTron
  • 17,012
  • 10
  • 94
  • 142
  • I am using nx as Fullstack single repo framework and your answer help me to set the inspector port of a Nest application because it was changing on every run "serve": { "builder": "@nrwl/node:execute", "options": { "buildTarget": "api:build", "inspect": true, "port": 9229 } } – 80sax May 07 '20 at 17:51
-1

ng serve --port 4202 --host 192.175.0.48 --open

Ayush Sahu
  • 268
  • 3
  • 15