How to change the corner port from 4200 to any other

I want to use 5000 instead of 4200.

What I tried, I created a file with the root name ember-cli and put the JSON according to the code below:

 { "port": 5000 } 

But my application still runs on 4200 instead of 5000

+178
angular-cli
Nov 21 '16 at 10:02
source share
19 answers

The solution for me was

 ng serve --port 4401 

(You can change 4401 to any number you want)

Then launch the browser -> http: // localhost: 4401 /

Basically, I had two Applications and with the help of the above approach, now I can run both of them simultaneously in my development environment.

+282
Jul 27 '17 at 18:40
source share

You can change the application port by entering the following command:

ng feed --port 4200

Also for permanent configuration, you can change the port by editing the angular-cli.json file

  "defaults": { "serve": { "port": 8080 } } 
+104
Jul 06 '17 at 6:40
source share

Changing nodel_modules/angular-cli/commands/server.js is a bad idea as it will be updated when a new version of angular-cli . Instead, you should specify ng serve --port 5000 in package.json as follows:

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

You can also specify a host with - host 127.0.0.1

+51
Mar 16 '17 at 9:29
source share

It seems that everything has changed in recent versions of the CLI (I am using 6.0.1 ). I was able to change the default port used by ng serve by adding the port option to my angular.json project:

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

(Only relevant properties are shown in this example.)

+50
May 14 '18 at 12:41
source share

The location of the port settings has changed a couple of times.

When using Angular CLI 1

Edit angular-cli.json

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

If using the latest version of Angular CLI

Edit angular.json

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

Without changing any file

Run the command

 ng serve --host 0.0.0.0 --port 5000 
+34
Jul 04 '18 at 13:43
source share

No one has updated the answer for the latest Angular CLI. With the latest Angular CLI

In the latest version angular-cli, in which angular-cli.json is renamed to angular.json , you can change the port by editing the angular.json file which now specifies the port for each "project"

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

More on this here

+18
Sep 15 '18 at 14:22
source share

I usually use the ng set command to change the Angular CLI settings for the project level.

 ng set defaults.serve.port=4201 

It changes your .angular.cli.json and adds the port settings, as mentioned earlier .

After this change, you can just use ng serve and it will use the preferred port without having to specify it every time.

+14
Jan 27 '18 at 14:48
source share

you can also enter the following command in your angular kli, where you usually type npm start

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

+8
Jul 12 '17 at 14:05
source share
  • For permanent:

    Go to nodel_modules / angular -cli / commands / server.js Find var defaultPort = process.env.PORT || 4200; and change 4200 to whatever you want.

  • To execute now:

    ng serve --port 4500 (you change 4500 to any number you want to use as your port)

+6
Feb 09 '17 at 9:15
source share

you can also write this command: ng serve -p 5000

+6
Nov 15 '17 at 11:40
source share

in angular 2 ++.

To change the port, you can run the following command in the terminal:

 ng serve --host 0.0.0.0 --port 5000. 
+4
Aug 05 '18 at 15:13
source share

You can change the default port number that is configured in the serve.js file.

The path will be project_direcory/node_modules/angular-cli/commands/serve.js .

Search for this line -> var defaultPort = process.env.PORT || 4200; var defaultPort = process.env.PORT || 4200;
Replace this line -> var defaultPort = process.env.PORT || 5000; var defaultPort = process.env.PORT || 5000;

+3
Nov 21 '16 at 11:40
source share

just run ng serve --port 5000 --open

+3
Feb 26 '18 at 21:43
source share

Run the command below for 4200

 ng serve --port 4500 
+3
May 03 '18 at 6:32
source share

In angular.json:

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

I am using Angular-Cli. It worked for me.

+3
Jul 23 '18 at 21:04
source share

Although there are many valid solutions in the above answers, here is a visual guide and a specific solution for Angular 7 projects (possibly earlier versions, but no guarantees) using Visual Studio code. Locate schema.json in the directories as shown in the image tree, and change the integer in the port β†’ default section to constantly change the port in the browser.

enter image description here

+2
Dec 20 '18 at 16:48
source share

go to this file

 node_modules\@angular-devkit\build-angular\src\dev-server\schema.json 

and search port

 "port": { "type": "number", "description": "Port to listen on.", "default": 4200 }, 

change by default everything you want and restart the server

+2
Apr 16 '19 at 5:57
source share

Just run

ng serve --port your port

Example:

ng serve --port 4401

+1
Jul 01 '19 at 13:29
source share

We have two ways to change the default port number in Angular.

The first way to cli command:

 ng serve --port 2400 --open 

The second way is to configure in the location: ProjectName\node_modules\@angular-devkit\build-angular\src\dev-server\schema.json .

Make changes to the schema.json file.

 { "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 }, 
0
Nov 26 '18 at 17:15
source share



All Articles