我想用5000而不是4200。

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

{
   "port": 5000
}

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


当前回答

简单设置在包中。json文件

"scripts": {
    "ng": "ng",
    "start": "ng serve --port 3000",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

然后运行命令

npm start

其他回答

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

ng serve --port 4401    

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

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

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

转到angular。json文件,

搜索关键字“serve”:

添加port关键字如下所示:

 "serve": {
     "builder": "@angular-devkit/build-angular:dev-server",
     "options": {
         "browserTarget": "my-new-angular-app:build",
         "port": 3001
     },
     ...

在package.json中设置你的首选项

-o或——open是在浏览器中自动运行应用程序

使用NPM start或ng serve运行应用程序

"scripts": {
"start": "ng serve --port 4500 -o"
}

不建议更改节点模块,因为更新或重新安装可能会删除这些更改。所以最好在angular cli中进行更改

Angular .json中的Angular 9

{
    "projects": {
            "targets": {
                "serve": {
                    "options": {
                         "port": 5000
                     }
                }     
            }     
    }
}  

虽然上面的答案中已经有很多有效的解决方案,但这里是一个使用visual Studio Code的Angular 7项目的可视化指南和具体解决方案(也可能是更早的版本,但不保证)。定位模式。在图像树中显示的目录中添加Json,并更改port——> default下的整数,以永久更改浏览器中的端口。