我想用5000而不是4200。

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

{
   "port": 5000
}

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


当前回答

要在运行时更改一次端口,并且没有更改配置,您可以使用以下命令

ng serve --port 5000

如果每次运行ng服务都需要5000端口。使用以下方法

使用angular.json

在“选项”字段下搜索“服务”,如下所示:

在node_modules > @angular-devkit > build-angular > src > dev-server > schema中。Json,你会发现下面的代码和更新端口,如你想要的5000。 在包中。Json下的“脚本”,我们已经“开始”更新它与下面的命令,所以每次运行“npm开始”,它将服务于5000。

注意:在终端中使用'ng serve'或'npm start'发布所有的重启服务器反馈有助于改进。谢谢!

其他回答

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

ng serve --port 4401    

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

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

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

没有人更新了最新的Angular CLI的答案。使用最新的Angular CLI

使用最新版本的angular-cli。Json重命名为angular。Json,你可以通过编辑angular改变端口。json文件 现在您可以为每个“项目”指定一个端口。

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

点击这里阅读更多信息

在包中。Json,查找ng serve命令。 将ng serve命令替换为ng serve——port 4201。 然后在终端使用npm启动或yarn启动。 它应该会起作用。

如果你有多个Angular app,你可以为它们指定不同的端口,并同时运行它们。

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

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