我想用5000而不是4200。

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

{
   "port": 5000
}

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


当前回答

你也可以在通常输入NPM start的angular cli中输入下面的命令

Ng服务器——主机“ip-address”——端口“port-number”

其他回答

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

ng serve --port 4401    

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

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

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

对于角10+:

导航到angular。json文件。 搜索“serve”字段。 在“服务”下面是“选项”字段(如果不存在,添加选项字段)。 将这一行添加到“options”: "port": 4333(你想要的任何端口)。

例子:

        "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "port": 4333
      },
      "configurations": {
        "production": {
          "browserTarget": "dashboard:build:production"
        }
      }
    },

在Angular中,我们有两种改变默认端口号的方法。

cli命令的第一种方式:

ng serve --port 2400 --open

第二种方法是在以下位置进行配置:ProjectName\node_modules\@angular-devkit\build-angular\src\dev-server\schema.json。

在模式中进行更改。json文件。

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

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

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

转到这个文件

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

搜索端口

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

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