I want to use 5000 instead of 4200.
I have tried to create a file on root name ember-cli
and put JSON according to the code below:
{
&q
This will automatically open your window as well
ng serve -o --port 4801
You can edit default port number that is configured in serve.js file.
Path will be project_direcory/node_modules/angular-cli/commands/serve.js
.
Search for this line -> var defaultPort = process.env.PORT || 4200;
Replace with this line -> var defaultPort = process.env.PORT || 5000;
To run and open in the browser automatically use the flag -open
or just -o
ng serve -o --port 4200
Note: The port 4200 is arbitrary. It can be any port of your choice
Changing nodel_modules/angular-cli/commands/server.js
is a bad idea as it will be updated when you install new version of angular-cli
. Instead you should specify ng serve --port 5000 in package.json
like this:
"scripts": {
"start": "ng serve --port 5000"
}
You can also specify host with --host 127.0.0.1
I usually use the ng set
command to change the Angular CLI settings for project level.
ng set defaults.serve.port=4201
It changes change your .angular.cli.json
and adds the port settings as it mentioned earlier.
After this change you can use simply ng serve
and it going to use the prefered port without the need of specifying it every time.