Angular 6+ How to change default port 4200

Sami-L picture Sami-L · May 25, 2018 · Viewed 57k times · Source

This question is specific to version 6 of Angular, not earlier, since .angular-cli.json file had been replaced by angular.json file.

I created a new Angular 6 project and tried, as I always did with previous versions, to change its default port but this time in angular.json.

  "defaults": {
    "serve": {
      "port": 4220
  },  

But get the following error:

Invalid schema detected in .angular-cli.json, please correct and try again!

Does any one know how to do this with this new version of Angular ?

Answer

Sami-L picture Sami-L · May 25, 2018

Due to a non accurate title: "angular-cli server - how to specify default port", it was hard to find an answer to my question, but thanks to Vladymir Gonzalez I did.

To help others find the answer quickly, I extracted here the specific part for Angular 6, belonging to elwyn :

Update for @angular/[email protected]: In the new angular.json you now specify a port per "project"

"projects": {
    "my-cool-project": {
        ... rest of project config omitted
        "architect": {
            "serve": {
                "options": {
                    "port": 4850    <-- add your custom port number here      
                }
            }
        }
    }
}

All options available:

https://github.com/angular/angular-cli/wiki/angular-workspace