Search code examples
angularangular-cli

Set default host and port for ng serve in config file


I want to know if i can set a host and a port in a config file so I don't have to type

ng serve --host foo.bar --port 80

instead of just

ng serve

Solution

  • Angular CLI 6+

    In the latest version of Angular, this is set in the angular.json config file. Example:

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

    You can also use ng config to view/edit values:

    ng config projects["my-project"].architect["serve"].options {port:4444}
    

    Angular CLI <6

    In previous versions, this was set in angular-cli.json underneath the defaults element:

    {
      "defaults": {
        "serve": {
          "port": 4444,
          "host": "10.1.2.3"
        }
      }
    }