22

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?

3 Answers 3

37

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

Sign up to request clarification or add additional context in comments.

3 Comments

for access from other pcs in the same network use this: "start": "ng serve --port 3000 --host x.x.x.x" and change x to server ip
But he wants to set it in .angular-cli.json. How would he do that?
Take note, that the schema has changed and placing a port value in the root under serve will cause an error. It needs to be nested under options as in the other answer provided
15

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"

1 Comment

This should be the correct way while using in Prod instead using cli commands
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.