How to change angular port from 4200 to any other

后端 未结 29 1598
心在旅途
心在旅途 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:03

    in angular 2++.

    To change port you can run below command in terminal :

    ng serve --host 0.0.0.0 --port 5000.
    
    0 讨论(0)
  • 2020-12-04 06:04

    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: ProjectName\node_modules\@angular-devkit\build-angular\src\dev-server\schema.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
        },
    
    0 讨论(0)
  • 2020-12-04 06:05

    Go to angular.json file,

    Search for keyword "serve":

    Add port keyword as shown below:

     "serve": {
         "builder": "@angular-devkit/build-angular:dev-server",
         "options": {
             "browserTarget": "my-new-angular-app:build",
             "port": 3001
         },
         ...
    
    0 讨论(0)
  • 2020-12-04 06:05

    This worked for all users:

    ng s -o --port 4450
    

    serve:

    s
    

    Builds and serves your app, rebuilding on file changes.

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

    For angular 10+:

    1. Navigate to angular.json file.
    2. Search for the "serve" field.
    3. Under "serve" it will the "options" field.
    4. Add this line to "options": "port": 4202(any port that you want).

    Example:

            "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "dashboard:build",
            **"port": 4202**
          },
          "configurations": {
            "production": {
              "browserTarget": "dashboard:build:production"
            }
          }
        },
    
    0 讨论(0)
  • 2020-12-04 06:08

    You can change your application port by entering the following command,

    ng serve --port 4200

    Also, for a permanent setup you can change the port by editing angular-cli.json file

     "defaults": {
        "serve": {
          "port": 8080
        }
      }
    
    0 讨论(0)
提交回复
热议问题