angular-cli

How to change angular port from 4200 to any other


I want to use 5000 instead of 4200.

I have tried to create a file on root name ember-cli and put JSON according to the code below:

{
   "port": 5000
}

But my app still runs on 4200 instead of 5000


Solution

  • It seems things have changed in recent versions of the CLI (I'm using 6.0.1). I was able to change the default port used by ng serve by adding a port option to my project's angular.json:

    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "projects": {
            "my-project": {
                "architect": {
                    "serve": {
                        "options": {
                            "port": 4201
                        }
                    }
                }
            }
        }
    }
    

    (Only relevant properties are shown in this example.)