Q . Set default host and port for ng serve in config file.

@mit $ingh. asked, Jul 28 ' 2017

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 www.codeman.in --port 80

instead of just

ng serve
  • angularJS
  • config
  • hostname
  • port
  • ng-serve
  • angular-cli

4 Answers

As of recent versions of Angular CLI (v1.0.0-rc.0 at least but perhaps earlier) you can now set these directly in angular-cli.json underneath the defaults element:

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

 

As of right now that feature is not supported, however if this is something that bothers you an alternative would be in your package.json...

"scripts": {
  "start": "ng serve --host www.codeman.in --port 80"
}

This way you can simply run npm start

Another option if you want to do this across multiple projects is to create an alias, which you can potentially name ngserve which will execute your above command.

You can configure the default HTTP port and the one used by the LiveReload server with two command-line options :

ng serve --host 0.0.0.0 --port 4201 --live-reload-port 49153

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

You can save these in a file, but you have to to put it in .ember-cli (at the moment, at least); see https://github.com/angular/angular-cli/issues/1156#issuecomment-227412924

{
"port": 4201,
"liveReload": true,
"host": "dev.domain.org",
"live-reload-port": 49153
}

edit: you can now set these in angular-cli.json as of commit https://github.com/angular/angular-cli/commit/da255b0808dcbe2f9da62086baec98dacc4b7ec9, which is in build 1.0.0-beta.30

Leave a Ansewer