我想用5000而不是4200。

我尝试在根名称ember-cli上创建一个文件,并按照下面的代码放置JSON:

{
   "port": 5000
}

但我的应用程序仍然运行在4200,而不是5000


当前回答

对我来说有效的解决方法是

ng serve --port 4401    

(你可以把4401改成任何你想要的号码)

然后启动浏览器-> http://localhost:4401/

基本上,我有两个应用程序,在上述方法的帮助下,现在我能够在我的开发环境中同时运行它们。

其他回答

在CLI的最新版本(我使用的是6.0.1)中,情况似乎发生了变化。我可以通过在项目的angular.json中添加一个port选项来改变ng serve使用的默认端口:

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "projects": {
        "my-project": {
            "architect": {
                "serve": {
                    "options": {
                        "port": 4201
                    }
                }
            }
        }
    }
}

(本例中只显示相关属性。)

端口设置的位置已经更改了几次。

如果使用Angular CLI

改变angular-cli.json

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

如果使用最新的Angular CLI

改变angular.json

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

无需更改任何文件

执行命令

ng serve --host 0.0.0.0 --port 5000

在angular项目中更改端口号的方法:

Node_modules \ @angular-devkit\build-angular\src\dev-server\schemaJson文件

    "port": {
             "type": "number",
             "description": "Port to listen on.",
             "default": <<port number>>     /* write your required port number here */
   } 

使用以下命令运行项目

    ng serve --port <<port number>> --open

在角。json文件

   "server": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
          "browserTarget": "projectname:build",
          "port": 5000   /* add this part */
         }
adding this part and starting the server.

转到这个文件

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

搜索端口

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

更改默认值并重新启动服务器

对我来说有效的解决方法是

ng serve --port 4401    

(你可以把4401改成任何你想要的号码)

然后启动浏览器-> http://localhost:4401/

基本上,我有两个应用程序,在上述方法的帮助下,现在我能够在我的开发环境中同时运行它们。