How to change angular port from 4200 to any other

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

    goto this file

    node_modules\@angular-devkit\build-angular\src\dev-server\schema.json
    

    and search port

    "port": {
      "type": "number",
      "description": "Port to listen on.",
      "default": 4200
    },
    

    change default value whatever you want and restart the server

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

    You can try:

    ng serve --host 0.0.0.0 --port 4001
    

    Then launch browser with: http://localhost:4001/

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

    Run below command for other than 4200

    ng serve --port 4500
    
    0 讨论(0)
  • 2020-12-04 06:20

    The location for port settings has changed a couple of times.

    If using Angular CLI 1

    Change angular-cli.json

    {
      "defaults": {
        "serve": {
          "host": "0.0.0.0",
          "port": 5000 
        }
      }
    }
    

    If using the latest Angular CLI

    Change angular.json

    "projects": {
        "project-name": {
            ...
            "architect": {
                "serve": {
                    "options": {
                      "host": "0.0.0.0",
                      "port": 5000
                    }
                }
            }
            ...
        }
    }
    

    Without changing any file

    Run the command

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

    The code worked for me was as follows

    ng serve --port ABCD
    

    For Example

    ng serve --port 6300
    
    0 讨论(0)
  • 2020-12-04 06:21

    The solution worked for me was

    ng serve --port 4401    
    

    (You can change 4401 to whatever number you want)

    Then launch browser -> http://localhost:4401/

    Basically, I was having two Applications and with the help of the above approach now I am able to run both of them simultaneously in my development environment.

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