Jak zmienić port kątowy z 4200 na dowolny inny

Chcę użyć 5000 zamiast 4200 ..

Próbowałem stworzyć plik o nazwie root ember-cli i umieścić JSON zgodnie z poniższym kodem:

{
   "port": 5000
}

Ale moja aplikacja nadal działa na 4200 zamiast 5000

Author: Apostolos, 2016-11-21

15 answers

Rozwiązanie zadziałało dla mnie

ng serve --port 4401    

(możesz zmienić 4401 na dowolny numer)

Następnie uruchom przeglądarkę - > http://localhost:4401/

Zasadniczo miałem dwie aplikacje i z pomocą powyższego podejścia teraz jestem w stanie uruchomić obie jednocześnie w moim środowisku programistycznym.

 118
Author: David,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-27 20:02:41

Możesz zmienić port aplikacji, wpisując następujące polecenie,

Ng serve --port 4200

Ponadto, aby uzyskać stałą konfigurację, możesz zmienić port, edytując angular-cli.plik json

 "defaults": {
    "serve": {
      "port": 8080
    }
  }
 77
Author: ganesh kalje,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-03 13:24:34

Zmiana nodel_modules/angular-cli/commands/server.js jest złym pomysłem, ponieważ zostanie zaktualizowana po zainstalowaniu nowej wersji angular-cli. Zamiast tego należy podać ng serve --port 5000 W package.json w następujący sposób:

"scripts": {
    "start": "ng serve --port 5000"
}

Można również określić host za pomocą --host 127.0.0.1

 35
Author: Dhyey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-21 06:47:52

To się zmieniło kilka razy.

Jeśli używasz kątowego CLI 1

Zmień angular-cli.json

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

Jeśli używasz najnowszego Anfular CLI

Zmień angular.json

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

Bez zmiany jakiegokolwiek pliku

Uruchom polecenie

ng serve --host 0.0.0.0 --port 5000
 9
Author: arsanyf,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-04 13:43:10
  • Na Stałe:

    Goto nodel_modules/angular-cli/commands/server.js Szukaj var defaultPort = process.env.PORT || 4200; i zmień 4200 na cokolwiek chcesz.

  • Aby Uruchomić Teraz:

    Ng serve --port 4500 (Możesz zmienić 4500 na dowolną liczbę, której chcesz użyć jako portu)

 8
Author: Deepak swain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-09 09:15:05

Zwykle używam polecenia ng set, Aby zmienić ustawienia kątowe CLI dla poziomu projektu.

ng set defaults.serve.port=4201

Zmienia Twoje .angular.cli.json i dodaje ustawienia portu jako , o którym wspomniano wcześniej .

Po tej zmianie można użyć po prostu ng serve i będzie on używał preferowanego portu bez konieczności każdorazowego jego określania.

 8
Author: csikosjanos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-01-27 14:54:17

Wygląda na to, że coś się zmieniło w ostatnich wersjach CLI(używam 6.0.1). Udało mi się zmienić domyślny port używany przez ng serve dodając opcję port do angular.json mojego projektu:

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

(w tym przykładzie pokazano tylko odpowiednie właściwości.)

 8
Author: Nathan Friend,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-14 12:41:24

Możesz również wprowadzić poniższe polecenie w swoim CLI angular, gdzie zwykle wpisujesz npm start

Ng serve --host "ip-address" -- port "port-number"

 7
Author: Ajitesh Jaiswal,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-07-12 14:05:39

Możesz edytować domyślny numer portu skonfigurowany w serwie.plik js.

Ścieżka będzie project_direcory/node_modules/angular-cli/commands/serve.js.

Szukaj tej linii -> var defaultPort = process.env.PORT || 4200;
Zastąp tą linią -> var defaultPort = process.env.PORT || 5000;

 4
Author: Amruth LS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-21 11:50:15

Możesz również napisać to polecenie: ng serve -p 5000

 3
Author: Sara Vaseei,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-15 11:40:10

Uruchom poniżej polecenia dla innych niż 4200

ng serve --port 4500
 3
Author: Sagar Jadhav,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-05-03 06:32:43

Nikt nie zaktualizował odpowiedzi na najnowsze Cli Angular.Z najnowszymi Angular CLI

Z latest version angular-cli, w którym angular-cli.JSON przemianowany na angular.json , możesz zmienić port, edytując angular.json plik teraz określasz port na "project"

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

Czytaj więcej na ten temat here

 3
Author: Sajeetharan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-15 14:28:50

Simply run ng serve --port 5000 --open

 2
Author: Daniel Torres Laserna,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-26 21:43:46

In angular.json:

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
          "browserTarget": "projectname:build",
          "port": 5000
         }
Używam angular-cli. To mi pomogło.
 1
Author: user3158369,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-07-23 23:50:22

In angular 2++.

Aby zmienić port możesz uruchomić poniższe polecenie w Terminalu:

ng serve --host 0.0.0.0 --port 5000.
 0
Author: Nitya nand,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-08-05 16:52:22