Changing Server port on Angular 2

时间:2016-10-20 12:37:12

标签: angular

i am trying to change the default "4200" port.

I tried adding the bs-config.json under src like this:

 {
  "port": 9002,
  "files": ["./src/**/*.{html,htm,css,js}"],
  "server": { "baseDir": "./src" }
}

but it did not work. Moreover i searched in my whole project for port 4200 but i did not find the real configuration.

Please help me with this .

Thanks.

UPDATE

i added .ember-cli file in project root with custom port :

{
   "port": 9002
}

and it works.

2 个答案:

答案 0 :(得分:4)

Depends on what server software you're using, but based on your port and configuration it's most likely one of these:

Angular2-cli

If you are using something like

ng serve

You are using angular2-cli, and need to provide at port argument like so:

ng serve --port 9002

Source: https://github.com/angular/angular-cli#usage

lite-server

If you're using lite-server, your configuration looks correct, so ensure the configuration is loaded at startup. The console output normally says something like 'couldn't find bs-config.json, using default settings'

答案 1 :(得分:4)

angular cli提供默认端口4200.for更改端口号将serve json数据添加到" angular-cli.json"文件

 "defaults": {
"styleExt": "css",
"component": {},
"serve": {
  "port": 8080
}

}