Set default host and port for ng serve in config file












115















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









share|improve this question





























    115















    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









    share|improve this question



























      115












      115








      115


      25






      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









      share|improve this question
















      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






      angular angular-cli






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 13 '16 at 13:06









      Marek Grác

      199117




      199117










      asked Jun 11 '16 at 9:29









      cre8cre8

      6,90132141




      6,90132141
























          10 Answers
          10






          active

          oldest

          votes


















          159














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





          share|improve this answer





















          • 6





            To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

            – dman
            Jan 2 '18 at 21:14













          • VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

            – Ola Berntsson
            Mar 23 '18 at 19:53






          • 4





            It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

            – Nathan Friend
            May 14 '18 at 14:43



















          61














          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 foo.bar --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.






          share|improve this answer































            30














            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






            share|improve this answer































              24














              This changed in the latest Angular CLI.



              The file name changed to angular.json, and the structure also changed.



              This is what you should do:



              "projects": {
              "project-name": {
              ...
              "architect": {
              "serve": {
              "options": {
              "host": "foo.bar",
              "port": 80
              }
              }
              }
              ...
              }
              }





              share|improve this answer



















              • 1





                Worked for me with @angular/cli version 6.1.5

                – PHEDev
                Sep 13 '18 at 19:56






              • 1





                Worked for me with @angular/cli version 7.0.6

                – Kerry Jones
                Nov 20 '18 at 0:45



















              14














              Another option is to run ng serve command with the --port option e.g



              ng serve --port 5050 (i.e for port 5050)



              Alternatively, the command: ng serve --port 0, will auto assign an available port for use.






              share|improve this answer


























              • The --port 0 bit was nice info but I'm not sure it answers the question.

                – Ash
                Nov 27 '18 at 3:38



















              6














              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






              share|improve this answer

































                4














                We have two ways to change default port number in Angular.



                First way to cli command:



                ng serve --port 2400 --open



                Second way is by configuration at the location: ProjectNamenode_modules@angular-devkitbuild-angularsrcdev-serverschema.json.



                Make changes in schema.json file.



                {
                "title": "Dev Server Target",
                "description": "Dev Server target options for Build Facade.",
                "type": "object",
                "properties": {
                "browserTarget": {
                "type": "string",
                "description": "Target to serve."
                },
                "port": {
                "type": "number",
                "description": "Port to listen on.",
                "default": 2400
                },






                share|improve this answer





















                • 2





                  You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                  – Bjørn Lindner
                  Nov 30 '18 at 11:52



















                2














                If your are on windows you can do it this way :




                1. In your project root directory, Create file run.bat

                2. Add your command with your choice of configurations in this file. For Example



                ng serve --host 192.168.1.2 --open





                1. Now you can click and open this file whenever you want to serve.


                This not standard way but comfortable to use (which I feel).






                share|improve this answer

































                  0














                  here is what i put into package.json (running angular 6):



                  {
                  "name": "local-weather-app",
                  "version": "1.0.0",
                  "scripts": {
                  "ng": "ng",
                  "start": "ng serve --port 5000",
                  "build": "ng build",
                  "test": "ng test",
                  "lint": "ng lint",
                  "e2e": "ng e2e"
                  },


                  Then a plain npm start will pull in the contents of start. Could also add other options to contents






                  share|improve this answer

































                    0














                    enter image description here



                    Only one thing you have to do. Type this in in your Command Prompt:
                    ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.






                    share|improve this answer























                      Your Answer






                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "1"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37762125%2fset-default-host-and-port-for-ng-serve-in-config-file%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      10 Answers
                      10






                      active

                      oldest

                      votes








                      10 Answers
                      10






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      159














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





                      share|improve this answer





















                      • 6





                        To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                        – dman
                        Jan 2 '18 at 21:14













                      • VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                        – Ola Berntsson
                        Mar 23 '18 at 19:53






                      • 4





                        It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                        – Nathan Friend
                        May 14 '18 at 14:43
















                      159














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





                      share|improve this answer





















                      • 6





                        To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                        – dman
                        Jan 2 '18 at 21:14













                      • VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                        – Ola Berntsson
                        Mar 23 '18 at 19:53






                      • 4





                        It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                        – Nathan Friend
                        May 14 '18 at 14:43














                      159












                      159








                      159







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





                      share|improve this answer















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






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Feb 13 at 13:59

























                      answered Mar 14 '17 at 14:24









                      Toby JToby J

                      7,45153942




                      7,45153942








                      • 6





                        To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                        – dman
                        Jan 2 '18 at 21:14













                      • VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                        – Ola Berntsson
                        Mar 23 '18 at 19:53






                      • 4





                        It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                        – Nathan Friend
                        May 14 '18 at 14:43














                      • 6





                        To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                        – dman
                        Jan 2 '18 at 21:14













                      • VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                        – Ola Berntsson
                        Mar 23 '18 at 19:53






                      • 4





                        It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                        – Nathan Friend
                        May 14 '18 at 14:43








                      6




                      6





                      To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                      – dman
                      Jan 2 '18 at 21:14







                      To make things easier, you can specify 0.0.0.0 instead of the host ip to listen on all Ethernet devices. This way both local host and public ip address can be used.

                      – dman
                      Jan 2 '18 at 21:14















                      VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                      – Ola Berntsson
                      Mar 23 '18 at 19:53





                      VS2017 seems to ignore the port setting for some weird reason, but I used this trick with @dman 's addition (0.0.0.0 as host) to at least enable remote connections.

                      – Ola Berntsson
                      Mar 23 '18 at 19:53




                      4




                      4





                      It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                      – Nathan Friend
                      May 14 '18 at 14:43





                      It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.

                      – Nathan Friend
                      May 14 '18 at 14:43













                      61














                      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 foo.bar --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.






                      share|improve this answer




























                        61














                        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 foo.bar --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.






                        share|improve this answer


























                          61












                          61








                          61







                          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 foo.bar --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.






                          share|improve this answer













                          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 foo.bar --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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 13 '16 at 13:08









                          BroccoBrocco

                          40.2k85271




                          40.2k85271























                              30














                              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






                              share|improve this answer




























                                30














                                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






                                share|improve this answer


























                                  30












                                  30








                                  30







                                  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






                                  share|improve this answer













                                  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







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Nov 3 '16 at 7:24









                                  Shreekant NShreekant N

                                  6951823




                                  6951823























                                      24














                                      This changed in the latest Angular CLI.



                                      The file name changed to angular.json, and the structure also changed.



                                      This is what you should do:



                                      "projects": {
                                      "project-name": {
                                      ...
                                      "architect": {
                                      "serve": {
                                      "options": {
                                      "host": "foo.bar",
                                      "port": 80
                                      }
                                      }
                                      }
                                      ...
                                      }
                                      }





                                      share|improve this answer



















                                      • 1





                                        Worked for me with @angular/cli version 6.1.5

                                        – PHEDev
                                        Sep 13 '18 at 19:56






                                      • 1





                                        Worked for me with @angular/cli version 7.0.6

                                        – Kerry Jones
                                        Nov 20 '18 at 0:45
















                                      24














                                      This changed in the latest Angular CLI.



                                      The file name changed to angular.json, and the structure also changed.



                                      This is what you should do:



                                      "projects": {
                                      "project-name": {
                                      ...
                                      "architect": {
                                      "serve": {
                                      "options": {
                                      "host": "foo.bar",
                                      "port": 80
                                      }
                                      }
                                      }
                                      ...
                                      }
                                      }





                                      share|improve this answer



















                                      • 1





                                        Worked for me with @angular/cli version 6.1.5

                                        – PHEDev
                                        Sep 13 '18 at 19:56






                                      • 1





                                        Worked for me with @angular/cli version 7.0.6

                                        – Kerry Jones
                                        Nov 20 '18 at 0:45














                                      24












                                      24








                                      24







                                      This changed in the latest Angular CLI.



                                      The file name changed to angular.json, and the structure also changed.



                                      This is what you should do:



                                      "projects": {
                                      "project-name": {
                                      ...
                                      "architect": {
                                      "serve": {
                                      "options": {
                                      "host": "foo.bar",
                                      "port": 80
                                      }
                                      }
                                      }
                                      ...
                                      }
                                      }





                                      share|improve this answer













                                      This changed in the latest Angular CLI.



                                      The file name changed to angular.json, and the structure also changed.



                                      This is what you should do:



                                      "projects": {
                                      "project-name": {
                                      ...
                                      "architect": {
                                      "serve": {
                                      "options": {
                                      "host": "foo.bar",
                                      "port": 80
                                      }
                                      }
                                      }
                                      ...
                                      }
                                      }






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Jul 4 '18 at 13:46









                                      arsanyfarsanyf

                                      5531610




                                      5531610








                                      • 1





                                        Worked for me with @angular/cli version 6.1.5

                                        – PHEDev
                                        Sep 13 '18 at 19:56






                                      • 1





                                        Worked for me with @angular/cli version 7.0.6

                                        – Kerry Jones
                                        Nov 20 '18 at 0:45














                                      • 1





                                        Worked for me with @angular/cli version 6.1.5

                                        – PHEDev
                                        Sep 13 '18 at 19:56






                                      • 1





                                        Worked for me with @angular/cli version 7.0.6

                                        – Kerry Jones
                                        Nov 20 '18 at 0:45








                                      1




                                      1





                                      Worked for me with @angular/cli version 6.1.5

                                      – PHEDev
                                      Sep 13 '18 at 19:56





                                      Worked for me with @angular/cli version 6.1.5

                                      – PHEDev
                                      Sep 13 '18 at 19:56




                                      1




                                      1





                                      Worked for me with @angular/cli version 7.0.6

                                      – Kerry Jones
                                      Nov 20 '18 at 0:45





                                      Worked for me with @angular/cli version 7.0.6

                                      – Kerry Jones
                                      Nov 20 '18 at 0:45











                                      14














                                      Another option is to run ng serve command with the --port option e.g



                                      ng serve --port 5050 (i.e for port 5050)



                                      Alternatively, the command: ng serve --port 0, will auto assign an available port for use.






                                      share|improve this answer


























                                      • The --port 0 bit was nice info but I'm not sure it answers the question.

                                        – Ash
                                        Nov 27 '18 at 3:38
















                                      14














                                      Another option is to run ng serve command with the --port option e.g



                                      ng serve --port 5050 (i.e for port 5050)



                                      Alternatively, the command: ng serve --port 0, will auto assign an available port for use.






                                      share|improve this answer


























                                      • The --port 0 bit was nice info but I'm not sure it answers the question.

                                        – Ash
                                        Nov 27 '18 at 3:38














                                      14












                                      14








                                      14







                                      Another option is to run ng serve command with the --port option e.g



                                      ng serve --port 5050 (i.e for port 5050)



                                      Alternatively, the command: ng serve --port 0, will auto assign an available port for use.






                                      share|improve this answer















                                      Another option is to run ng serve command with the --port option e.g



                                      ng serve --port 5050 (i.e for port 5050)



                                      Alternatively, the command: ng serve --port 0, will auto assign an available port for use.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited Oct 3 '18 at 10:39









                                      mvermand

                                      2,56722447




                                      2,56722447










                                      answered Jan 26 '18 at 7:59









                                      MwizakMwizak

                                      1,70921114




                                      1,70921114













                                      • The --port 0 bit was nice info but I'm not sure it answers the question.

                                        – Ash
                                        Nov 27 '18 at 3:38



















                                      • The --port 0 bit was nice info but I'm not sure it answers the question.

                                        – Ash
                                        Nov 27 '18 at 3:38

















                                      The --port 0 bit was nice info but I'm not sure it answers the question.

                                      – Ash
                                      Nov 27 '18 at 3:38





                                      The --port 0 bit was nice info but I'm not sure it answers the question.

                                      – Ash
                                      Nov 27 '18 at 3:38











                                      6














                                      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






                                      share|improve this answer






























                                        6














                                        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






                                        share|improve this answer




























                                          6












                                          6








                                          6







                                          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






                                          share|improve this answer















                                          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







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Feb 8 '17 at 15:24

























                                          answered Jan 13 '17 at 15:07









                                          Dan MitchellDan Mitchell

                                          540613




                                          540613























                                              4














                                              We have two ways to change default port number in Angular.



                                              First way to cli command:



                                              ng serve --port 2400 --open



                                              Second way is by configuration at the location: ProjectNamenode_modules@angular-devkitbuild-angularsrcdev-serverschema.json.



                                              Make changes in schema.json file.



                                              {
                                              "title": "Dev Server Target",
                                              "description": "Dev Server target options for Build Facade.",
                                              "type": "object",
                                              "properties": {
                                              "browserTarget": {
                                              "type": "string",
                                              "description": "Target to serve."
                                              },
                                              "port": {
                                              "type": "number",
                                              "description": "Port to listen on.",
                                              "default": 2400
                                              },






                                              share|improve this answer





















                                              • 2





                                                You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                                – Bjørn Lindner
                                                Nov 30 '18 at 11:52
















                                              4














                                              We have two ways to change default port number in Angular.



                                              First way to cli command:



                                              ng serve --port 2400 --open



                                              Second way is by configuration at the location: ProjectNamenode_modules@angular-devkitbuild-angularsrcdev-serverschema.json.



                                              Make changes in schema.json file.



                                              {
                                              "title": "Dev Server Target",
                                              "description": "Dev Server target options for Build Facade.",
                                              "type": "object",
                                              "properties": {
                                              "browserTarget": {
                                              "type": "string",
                                              "description": "Target to serve."
                                              },
                                              "port": {
                                              "type": "number",
                                              "description": "Port to listen on.",
                                              "default": 2400
                                              },






                                              share|improve this answer





















                                              • 2





                                                You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                                – Bjørn Lindner
                                                Nov 30 '18 at 11:52














                                              4












                                              4








                                              4







                                              We have two ways to change default port number in Angular.



                                              First way to cli command:



                                              ng serve --port 2400 --open



                                              Second way is by configuration at the location: ProjectNamenode_modules@angular-devkitbuild-angularsrcdev-serverschema.json.



                                              Make changes in schema.json file.



                                              {
                                              "title": "Dev Server Target",
                                              "description": "Dev Server target options for Build Facade.",
                                              "type": "object",
                                              "properties": {
                                              "browserTarget": {
                                              "type": "string",
                                              "description": "Target to serve."
                                              },
                                              "port": {
                                              "type": "number",
                                              "description": "Port to listen on.",
                                              "default": 2400
                                              },






                                              share|improve this answer















                                              We have two ways to change default port number in Angular.



                                              First way to cli command:



                                              ng serve --port 2400 --open



                                              Second way is by configuration at the location: ProjectNamenode_modules@angular-devkitbuild-angularsrcdev-serverschema.json.



                                              Make changes in schema.json file.



                                              {
                                              "title": "Dev Server Target",
                                              "description": "Dev Server target options for Build Facade.",
                                              "type": "object",
                                              "properties": {
                                              "browserTarget": {
                                              "type": "string",
                                              "description": "Target to serve."
                                              },
                                              "port": {
                                              "type": "number",
                                              "description": "Port to listen on.",
                                              "default": 2400
                                              },







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Nov 26 '18 at 18:00

























                                              answered Nov 26 '18 at 17:49









                                              Satyendra PatelSatyendra Patel

                                              762




                                              762








                                              • 2





                                                You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                                – Bjørn Lindner
                                                Nov 30 '18 at 11:52














                                              • 2





                                                You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                                – Bjørn Lindner
                                                Nov 30 '18 at 11:52








                                              2




                                              2





                                              You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                              – Bjørn Lindner
                                              Nov 30 '18 at 11:52





                                              You do not want to override or change source files. angular.json is the correct way to override schema defaults, as mentioned in the accepted answer.

                                              – Bjørn Lindner
                                              Nov 30 '18 at 11:52











                                              2














                                              If your are on windows you can do it this way :




                                              1. In your project root directory, Create file run.bat

                                              2. Add your command with your choice of configurations in this file. For Example



                                              ng serve --host 192.168.1.2 --open





                                              1. Now you can click and open this file whenever you want to serve.


                                              This not standard way but comfortable to use (which I feel).






                                              share|improve this answer






























                                                2














                                                If your are on windows you can do it this way :




                                                1. In your project root directory, Create file run.bat

                                                2. Add your command with your choice of configurations in this file. For Example



                                                ng serve --host 192.168.1.2 --open





                                                1. Now you can click and open this file whenever you want to serve.


                                                This not standard way but comfortable to use (which I feel).






                                                share|improve this answer




























                                                  2












                                                  2








                                                  2







                                                  If your are on windows you can do it this way :




                                                  1. In your project root directory, Create file run.bat

                                                  2. Add your command with your choice of configurations in this file. For Example



                                                  ng serve --host 192.168.1.2 --open





                                                  1. Now you can click and open this file whenever you want to serve.


                                                  This not standard way but comfortable to use (which I feel).






                                                  share|improve this answer















                                                  If your are on windows you can do it this way :




                                                  1. In your project root directory, Create file run.bat

                                                  2. Add your command with your choice of configurations in this file. For Example



                                                  ng serve --host 192.168.1.2 --open





                                                  1. Now you can click and open this file whenever you want to serve.


                                                  This not standard way but comfortable to use (which I feel).







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Jan 1 at 6:06

























                                                  answered Jan 1 at 3:28









                                                  SankeerthSankeerth

                                                  316




                                                  316























                                                      0














                                                      here is what i put into package.json (running angular 6):



                                                      {
                                                      "name": "local-weather-app",
                                                      "version": "1.0.0",
                                                      "scripts": {
                                                      "ng": "ng",
                                                      "start": "ng serve --port 5000",
                                                      "build": "ng build",
                                                      "test": "ng test",
                                                      "lint": "ng lint",
                                                      "e2e": "ng e2e"
                                                      },


                                                      Then a plain npm start will pull in the contents of start. Could also add other options to contents






                                                      share|improve this answer






























                                                        0














                                                        here is what i put into package.json (running angular 6):



                                                        {
                                                        "name": "local-weather-app",
                                                        "version": "1.0.0",
                                                        "scripts": {
                                                        "ng": "ng",
                                                        "start": "ng serve --port 5000",
                                                        "build": "ng build",
                                                        "test": "ng test",
                                                        "lint": "ng lint",
                                                        "e2e": "ng e2e"
                                                        },


                                                        Then a plain npm start will pull in the contents of start. Could also add other options to contents






                                                        share|improve this answer




























                                                          0












                                                          0








                                                          0







                                                          here is what i put into package.json (running angular 6):



                                                          {
                                                          "name": "local-weather-app",
                                                          "version": "1.0.0",
                                                          "scripts": {
                                                          "ng": "ng",
                                                          "start": "ng serve --port 5000",
                                                          "build": "ng build",
                                                          "test": "ng test",
                                                          "lint": "ng lint",
                                                          "e2e": "ng e2e"
                                                          },


                                                          Then a plain npm start will pull in the contents of start. Could also add other options to contents






                                                          share|improve this answer















                                                          here is what i put into package.json (running angular 6):



                                                          {
                                                          "name": "local-weather-app",
                                                          "version": "1.0.0",
                                                          "scripts": {
                                                          "ng": "ng",
                                                          "start": "ng serve --port 5000",
                                                          "build": "ng build",
                                                          "test": "ng test",
                                                          "lint": "ng lint",
                                                          "e2e": "ng e2e"
                                                          },


                                                          Then a plain npm start will pull in the contents of start. Could also add other options to contents







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Jul 26 '18 at 12:24









                                                          Marian Nasry

                                                          755818




                                                          755818










                                                          answered Jul 26 '18 at 11:22









                                                          John DuggerJohn Dugger

                                                          11




                                                          11























                                                              0














                                                              enter image description here



                                                              Only one thing you have to do. Type this in in your Command Prompt:
                                                              ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.






                                                              share|improve this answer




























                                                                0














                                                                enter image description here



                                                                Only one thing you have to do. Type this in in your Command Prompt:
                                                                ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.






                                                                share|improve this answer


























                                                                  0












                                                                  0








                                                                  0







                                                                  enter image description here



                                                                  Only one thing you have to do. Type this in in your Command Prompt:
                                                                  ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.






                                                                  share|improve this answer













                                                                  enter image description here



                                                                  Only one thing you have to do. Type this in in your Command Prompt:
                                                                  ng serve --port 4021 [or any other port you want to assign eg: 5050, 5051 etc ]. No need to do changes in files.







                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Oct 4 '18 at 0:00









                                                                  Shahbaz Ali KhanShahbaz Ali Khan

                                                                  85




                                                                  85






























                                                                      draft saved

                                                                      draft discarded




















































                                                                      Thanks for contributing an answer to Stack Overflow!


                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                      But avoid



                                                                      • Asking for help, clarification, or responding to other answers.

                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                      To learn more, see our tips on writing great answers.




                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function () {
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37762125%2fset-default-host-and-port-for-ng-serve-in-config-file%23new-answer', 'question_page');
                                                                      }
                                                                      );

                                                                      Post as a guest















                                                                      Required, but never shown





















































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown

































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown







                                                                      Popular posts from this blog

                                                                      Monofisismo

                                                                      Angular Downloading a file using contenturl with Basic Authentication

                                                                      Olmecas