Angular 6+ How to change default port 4200

Due to a non accurate title: "angular-cli server - how to specify default port", it was hard to find an answer to my question, but thanks to Vladymir Gonzalez I did.

To help others find the answer quickly, I extracted here the specific part for Angular 6, belonging to elwyn :

Update for @angular/[email protected]: In the new angular.json you now specify a port per "project"

"projects": {
    "my-cool-project": {
        ... rest of project config omitted
        "architect": {
            "serve": {
                "options": {
                    "port": 4850    <-- add your custom port number here      
                }
            }
        }
    }
}

All options available:

https://github.com/angular/angular-cli/wiki/angular-workspace


The answer is simple write ng serve --open --port=YourPortNumber in command prompt.

Example :

ng serve --open --port=4201

==== OTHER SOLUTION ====

You can also change it in package.json

"scripts": {
  "start": "ng serve --open --port=4201",
}

Now, in command propmt just write npm start


I am giving answer for angular 2+ application.

If you wanted to start 2 angular application in different port i.e.

1) port 4200 
2) port 5000

you need to change "package.json" file and just change add one line "Script block" in first curly braces where your application name, version is default available,

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

Start your application by "npm start" command. This command will start your application on Port 5000.


You can always specify the port while serving also: ng serve --port 3000

You can put any valid port number there and it will serve from that port.