Set default host and port for ng serve in config file

cre8 picture cre8 · Jun 11, 2016 · Viewed 239.3k times · Source

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

Answer

Tobias J picture Tobias J · Mar 14, 2017

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"
    }
  }
}