How to change angular port from 4200 to any other

后端 未结 29 1599
心在旅途
心在旅途 2020-12-04 05:59

I want to use 5000 instead of 4200.

I have tried to create a file on root name ember-cli and put JSON according to the code below:

{
   &q         


        
相关标签:
29条回答
  • 2020-12-04 06:22

    No one has updated answer for latest Angular CLI.With latest Angular CLI

    With latest version of angular-cli in which angular-cli.json renamed to angular.json , you can change the port by editing angular.json file you now specify a port per "project"

    projects": {
        "my-cool-project": {
            ... rest of project config omitted
            "architect": {
                "serve": {
                    "options": {
                        "port": 4500
                    }
                }
            }
        }
    }
    

    Read more about it here

    0 讨论(0)
  • 2020-12-04 06:22

    you can also enter the below command in your angular cli where you normally enter npm start

    ng serve --host "ip-address" --port "port-number"

    0 讨论(0)
  • 2020-12-04 06:25

    Although there are already numerous valid solutions in the above answers, here is a visual guide and specific solution for Angular 7 projects (possibly earlier versions as well, no guarantees though) using Visual Studio Code. Locate the schema.json in the directories as shown in the image tree and alter the integer under port --> default for a permanent change of port in the browser.

    0 讨论(0)
  • 2020-12-04 06:26

    simply run ng serve --port 5000 --open

    0 讨论(0)
  • 2020-12-04 06:27

    Just Run

    ng serve --port yourport

    Example:

    ng serve --port 4401

    0 讨论(0)
  • 2020-12-04 06:28

    In angular.json:

    "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
              "browserTarget": "projectname:build",
              "port": 5000
             }
    

    I am using angular-cli. This worked for me.

    0 讨论(0)
提交回复
热议问题