Cómo cambiar el puerto angular de 4200 a cualquier otro


Quiero usar 5000 en lugar de 4200 ..

Lo que he intentado es que he creado un archivo en el nombre raíz ember-cli y poner JSON de acuerdo con el siguiente código:

{
   "port": 5000
}

Pero mi aplicación todavía se ejecuta en 4200 en lugar de 5000

Author: Apostolos, 2016-11-21

15 answers

La solución funcionó para mí fue

ng serve --port 4401    

(Puede cambiar 4401 a cualquier número que desee)

Luego inicie browser - > http://localhost:4401 /

Básicamente, tenía dos Aplicaciones y con la ayuda del enfoque anterior ahora puedo ejecutar ambas simultáneamente en mi entorno de desarrollo.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-27 20:02:41

Puede cambiar el puerto de su aplicación ingresando el siguiente comando,

Ng serve port port 4200

También, para una configuración permanente, puede cambiar el puerto editando angular-cli.json file

 "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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-03 13:24:34

Cambiar nodel_modules/angular-cli/commands/server.js es una mala idea, ya que se actualizará cuando instale una nueva versión de angular-cli. En su lugar, debe especificar ng serve port port 5000 en package.json así:

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

También puede especificar host con host 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-21 06:47:52

Esto ha cambiado un par de veces.

Si se utiliza Angular CLI 1

Change angular-cli.json

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

Si se utiliza la última CLI Anfular

Change angular.json

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

Sin cambiar ningún archivo

Ejecute el comando

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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-04 13:43:10
  • Para Permanente:

    Goto nodel_modules/angular-cli/commands/server.js Buscar var defaultPort = process.env.PORTAR / / 4200; y cambiar 4200 a cualquier otra cosa que desee.

  • Para Ejecutar Ahora:

    Ng serve port port 4500 (Cambia 4500 a cualquier número que quieras usar como tu puerto)

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-09 09:15:05

Normalmente uso el comando ng set para cambiar la configuración de Angular CLI para el nivel de proyecto.

ng set defaults.serve.port=4201

Cambia cambia tu .angular.cli.jsony agrega la configuración del puerto como se mencionó anteriormente.

Después de este cambio puede usar simplemente ng serve y va a usar el puerto preferido sin la necesidad de especificarlo cada vez.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-27 14:54:17

Parece que las cosas han cambiado en las versiones recientes de la CLI (estoy usando 6.0.1). Pude cambiar el puerto predeterminado utilizado por ng serve agregando una opción port a angular.json de mi proyecto:

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

(En este ejemplo solo se muestran las propiedades relevantes.)

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-14 12:41:24

También puede ingresar el siguiente comando en su cli angular donde normalmente ingresa npm start

Ng serve host host "ip-address" port 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-12 14:05:39

Puede editar el número de puerto predeterminado que está configurado en servir.archivo js.

La Ruta será project_direcory/node_modules/angular-cli/commands/serve.js.

Buscar esta línea -> var defaultPort = process.env.PORT || 4200;
Reemplazar con esta línea -> 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-21 11:50:15

También puede escribir este comando: 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-15 11:40:10

Ejecutar debajo del comando para otros que no sean 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-03 06:32:43

Nadie ha actualizado la respuesta para la última CLI de Angular.Con lo último Angular CLI

Con latest version de angular-cli en el que angular-cli.json renombrado a angular.json , puede cambiar el puerto editando angular.json archivo ahora especificar un puerto por "project"

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

Leer más 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-15 14:28:50

Simplemente ejecute 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-02-26 21:43:46

En angular.json:

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
          "browserTarget": "projectname:build",
          "port": 5000
         }

Estoy usando angular-cli. Esto funcionó para mí.

 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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-23 23:50:22

En angular 2++.

Para cambiar el puerto puede ejecutar el siguiente comando en la terminal:

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/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-05 16:52:22