Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-cli change port to 3000 in angular-cli.json

i use the material todo app from Daniel Zen and want to change to port in the angular-cli.json. https://github.com/danielzen/material-todo

But this doesn't work. I tried this:

{
  "port" : 3000,

But nothing happens. Anyone an idea?

like image 354
AnDoDri Avatar asked Dec 21 '16 10:12

AnDoDri


People also ask

Can we change the port number in Angular?

There are two ways we can change the default angular port number from 4200 to other number. Using ng serve --port flag. Specifying default port number in project's Angular. json file.

What is the command to change the default port of Angular?

Change Angular Port from 4200 via CLI command. Go to the Angular project directory and run the following command ng serve –port 4201 as shown below. E:\sneppets\Angular_workspace\my-app > ng serve --port 4201 chunk {main} main. js, main.


3 Answers

Edit with Angular-CLI 1.0.0

You can now directly define the used port in the .angular-cli.json file by defining the property like this:

{     "defaults": {         "serve": {             "port": 2500         }     } } 

Here is a direct link to all available options for the configuration: Angular-CLI options configuration

Old Answer

You can configure it directly in your packages.json, change your start scripts by:

"start": "ng serve --port 2500", 

And then run your server with npm start

like image 93
LoïcR Avatar answered Sep 27 '22 20:09

LoïcR


As in new version .angular-cli.json is not visible. You can set port in serve section of angular.json like this:

"serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "formation:build",
            "port": 5001
          },
 ....

You can add any port number instead of 5001

Thats how you can set your host aswell, just like port:

"host": "your_host_name"
like image 30
Zohab Ali Avatar answered Sep 27 '22 21:09

Zohab Ali


enter image description hereThis worked for me through the command line

ng serve --open --port 3000

I have checked with .angular-cli.json, but I am unable to find the same there.The typed command is highlighted in the image where the terminal is opened and in the second image the appication is ruuning on the port number 3000 which highlighted too

like image 38
Avinash Avatar answered Sep 27 '22 19:09

Avinash