angular-cli server - how to specify default port
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Using angular-cli with the ng serve
command, how can I specify a default port so I do not need to manually pass the --port
flag every time?
I'd like to change from port 4200.
angular angular-cli
add a comment |
Using angular-cli with the ng serve
command, how can I specify a default port so I do not need to manually pass the --port
flag every time?
I'd like to change from port 4200.
angular angular-cli
add a comment |
Using angular-cli with the ng serve
command, how can I specify a default port so I do not need to manually pass the --port
flag every time?
I'd like to change from port 4200.
angular angular-cli
Using angular-cli with the ng serve
command, how can I specify a default port so I do not need to manually pass the --port
flag every time?
I'd like to change from port 4200.
angular angular-cli
angular angular-cli
edited May 15 '18 at 21:56
elwyn
asked May 11 '16 at 6:38
elwynelwyn
5,61693544
5,61693544
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
Update for @angular/cli@6.x: and over
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": 1337
}
}
}
}
}
All options available:
https://github.com/angular/angular-cli/wiki/angular-workspace
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
Legacy:
Update for @angular/cli final:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Tested in angular-cli@1.0.0-beta.22-1
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
Restart the server and it will serve on that port.
There are more options specified here:
http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
add a comment |
In Angular 2 cli@2.3.1,
To run a new project on the different port, one way is to specify the port while you run ng serve command.
ng serve --port 4201
or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
... : ...,
... : ....
}
this way is much better where you don't need to define port explicitly every time.
add a comment |
Use npm scripts instead... Edit your package.json and add the command to script section.
{
"name": "my new project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080",
"lint": "tslint "src/**/*.ts" --project src/tsconfig.json --type-check && tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
Then just execute npm start
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
add a comment |
You can now specify the port in the .angular-cli.json under the defaults:
"defaults": {
"styleExt": "scss",
"serve": {
"port": 8080
},
"component": {}
}
Tested in angular-cli v1.0.6
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
add a comment |
For @angular/cli v6.2.1
The project configuration file angular.json
is able to handle multiple projects (workspaces) which can be individually served.
ng config projects.my-test-project.targets.serve.options.port 4201
Where the my-test-project
part is the project name what you set with the ng new
command just like here:
$ ng new my-test-project
$ cd my-test-project
$ ng config projects.my-test-project.targets.serve.options.port 4201
$ ng serve
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
Legacy:
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.
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
add a comment |
As far as Angular CLI: 7.1.4, there are two common ways to achieve changing the default port.
No. 1
In the angular.json
, add the --port
option to serve
part and use ng serve
to start the server.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 1337
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
}
}
},
No. 2
In the package.json
, add the --port
option to ng serve
and use npm start
to start the server.
"scripts": {
"ng": "ng",
"start": "ng serve --port 8000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
add a comment |
The answer provided by elwyn is correct. But you should also update protractor config for e2e.
In angular.json,
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 9000,
"browserTarget": "app:build"
}
}
In e2e/protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:9000/'
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37154813%2fangular-cli-server-how-to-specify-default-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Update for @angular/cli@6.x: and over
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": 1337
}
}
}
}
}
All options available:
https://github.com/angular/angular-cli/wiki/angular-workspace
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
Legacy:
Update for @angular/cli final:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Tested in angular-cli@1.0.0-beta.22-1
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
Restart the server and it will serve on that port.
There are more options specified here:
http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
add a comment |
Update for @angular/cli@6.x: and over
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": 1337
}
}
}
}
}
All options available:
https://github.com/angular/angular-cli/wiki/angular-workspace
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
Legacy:
Update for @angular/cli final:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Tested in angular-cli@1.0.0-beta.22-1
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
Restart the server and it will serve on that port.
There are more options specified here:
http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
add a comment |
Update for @angular/cli@6.x: and over
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": 1337
}
}
}
}
}
All options available:
https://github.com/angular/angular-cli/wiki/angular-workspace
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
Legacy:
Update for @angular/cli final:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Tested in angular-cli@1.0.0-beta.22-1
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
Restart the server and it will serve on that port.
There are more options specified here:
http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
Update for @angular/cli@6.x: and over
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": 1337
}
}
}
}
}
All options available:
https://github.com/angular/angular-cli/wiki/angular-workspace
Alternatively, you may specify the port each time when running ng serve like this:
ng serve --port 1337
Legacy:
Update for @angular/cli final:
Inside angular-cli.json
you can specify the port in the defaults:
"defaults": {
"serve": {
"port": 1337
}
}
Legacy-er:
Tested in angular-cli@1.0.0-beta.22-1
The server in angular-cli
comes from the ember-cli
project.
To configure the server, create an .ember-cli
file in the project root. Add your JSON config in there:
{
"port": 1337
}
Restart the server and it will serve on that port.
There are more options specified here:
http://ember-cli.com/#runtime-configuration
{
"skipGit" : true,
"port" : 999,
"host" : "0.1.0.1",
"liveReload" : true,
"environment" : "mock-development",
"checkForUpdates" : false
}
edited Mar 19 at 20:08
answered May 11 '16 at 6:38
elwynelwyn
5,61693544
5,61693544
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
add a comment |
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
It seems that things have changed in recent versions of the CLI (I'm using version 6). See here for more details.
– Nathan Friend
May 14 '18 at 14:41
add a comment |
In Angular 2 cli@2.3.1,
To run a new project on the different port, one way is to specify the port while you run ng serve command.
ng serve --port 4201
or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
... : ...,
... : ....
}
this way is much better where you don't need to define port explicitly every time.
add a comment |
In Angular 2 cli@2.3.1,
To run a new project on the different port, one way is to specify the port while you run ng serve command.
ng serve --port 4201
or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
... : ...,
... : ....
}
this way is much better where you don't need to define port explicitly every time.
add a comment |
In Angular 2 cli@2.3.1,
To run a new project on the different port, one way is to specify the port while you run ng serve command.
ng serve --port 4201
or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
... : ...,
... : ....
}
this way is much better where you don't need to define port explicitly every time.
In Angular 2 cli@2.3.1,
To run a new project on the different port, one way is to specify the port while you run ng serve command.
ng serve --port 4201
or the other way, you can edit your package.json file scripts part and attached the port to your start variable like I mentioned below and then simply run "npm start"
"scripts": {
"ng": "ng",
"start": "ng serve --port 4201",
... : ...,
... : ....
}
this way is much better where you don't need to define port explicitly every time.
edited May 29 '17 at 1:02
answered Dec 30 '16 at 1:20
ankit patelankit patel
1,495611
1,495611
add a comment |
add a comment |
Use npm scripts instead... Edit your package.json and add the command to script section.
{
"name": "my new project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080",
"lint": "tslint "src/**/*.ts" --project src/tsconfig.json --type-check && tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
Then just execute npm start
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
add a comment |
Use npm scripts instead... Edit your package.json and add the command to script section.
{
"name": "my new project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080",
"lint": "tslint "src/**/*.ts" --project src/tsconfig.json --type-check && tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
Then just execute npm start
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
add a comment |
Use npm scripts instead... Edit your package.json and add the command to script section.
{
"name": "my new project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080",
"lint": "tslint "src/**/*.ts" --project src/tsconfig.json --type-check && tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
Then just execute npm start
Use npm scripts instead... Edit your package.json and add the command to script section.
{
"name": "my new project",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0 --port 8080",
"lint": "tslint "src/**/*.ts" --project src/tsconfig.json --type-check && tslint "e2e/**/*.ts" --project e2e/tsconfig.json --type-check",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"core-js": "^2.4.1",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.26",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}
Then just execute npm start
edited Mar 27 '17 at 14:02
H. Pauwelyn
5,958184989
5,958184989
answered Jan 30 '17 at 22:43
David ValdiviesoDavid Valdivieso
161129
161129
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
add a comment |
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
This is the correct way to do this, permanently; so you don't have to specify the command-line parameter for --port every time. Also the --host param in this answer is required for running Angular 4 via Vagrant (or any remote system) so this kills 2 birds with one stone.
– Scott Byers
Apr 18 '17 at 2:55
add a comment |
You can now specify the port in the .angular-cli.json under the defaults:
"defaults": {
"styleExt": "scss",
"serve": {
"port": 8080
},
"component": {}
}
Tested in angular-cli v1.0.6
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
add a comment |
You can now specify the port in the .angular-cli.json under the defaults:
"defaults": {
"styleExt": "scss",
"serve": {
"port": 8080
},
"component": {}
}
Tested in angular-cli v1.0.6
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
add a comment |
You can now specify the port in the .angular-cli.json under the defaults:
"defaults": {
"styleExt": "scss",
"serve": {
"port": 8080
},
"component": {}
}
Tested in angular-cli v1.0.6
You can now specify the port in the .angular-cli.json under the defaults:
"defaults": {
"styleExt": "scss",
"serve": {
"port": 8080
},
"component": {}
}
Tested in angular-cli v1.0.6
answered May 31 '17 at 9:04
qorsmondqorsmond
72211124
72211124
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
add a comment |
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
Thank you!!! The same thing has been tested with @angular/cli: 1.3.0.
– Techno Cracker
Sep 26 '17 at 10:59
add a comment |
For @angular/cli v6.2.1
The project configuration file angular.json
is able to handle multiple projects (workspaces) which can be individually served.
ng config projects.my-test-project.targets.serve.options.port 4201
Where the my-test-project
part is the project name what you set with the ng new
command just like here:
$ ng new my-test-project
$ cd my-test-project
$ ng config projects.my-test-project.targets.serve.options.port 4201
$ ng serve
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
Legacy:
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.
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
add a comment |
For @angular/cli v6.2.1
The project configuration file angular.json
is able to handle multiple projects (workspaces) which can be individually served.
ng config projects.my-test-project.targets.serve.options.port 4201
Where the my-test-project
part is the project name what you set with the ng new
command just like here:
$ ng new my-test-project
$ cd my-test-project
$ ng config projects.my-test-project.targets.serve.options.port 4201
$ ng serve
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
Legacy:
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.
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
add a comment |
For @angular/cli v6.2.1
The project configuration file angular.json
is able to handle multiple projects (workspaces) which can be individually served.
ng config projects.my-test-project.targets.serve.options.port 4201
Where the my-test-project
part is the project name what you set with the ng new
command just like here:
$ ng new my-test-project
$ cd my-test-project
$ ng config projects.my-test-project.targets.serve.options.port 4201
$ ng serve
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
Legacy:
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.
For @angular/cli v6.2.1
The project configuration file angular.json
is able to handle multiple projects (workspaces) which can be individually served.
ng config projects.my-test-project.targets.serve.options.port 4201
Where the my-test-project
part is the project name what you set with the ng new
command just like here:
$ ng new my-test-project
$ cd my-test-project
$ ng config projects.my-test-project.targets.serve.options.port 4201
$ ng serve
** Angular Live Development Server is listening on localhost:4201, open your browser on http://localhost:4201/ **
Legacy:
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.
edited Sep 10 '18 at 17:11
answered Jan 27 '18 at 14:53
csikosjanoscsikosjanos
29336
29336
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
add a comment |
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
In Angular 6.0, I get 'set/get have been deprecated in favor of the config command', so this no longer works.
– VanAlbert
Sep 9 '18 at 0:17
add a comment |
As far as Angular CLI: 7.1.4, there are two common ways to achieve changing the default port.
No. 1
In the angular.json
, add the --port
option to serve
part and use ng serve
to start the server.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 1337
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
}
}
},
No. 2
In the package.json
, add the --port
option to ng serve
and use npm start
to start the server.
"scripts": {
"ng": "ng",
"start": "ng serve --port 8000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
add a comment |
As far as Angular CLI: 7.1.4, there are two common ways to achieve changing the default port.
No. 1
In the angular.json
, add the --port
option to serve
part and use ng serve
to start the server.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 1337
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
}
}
},
No. 2
In the package.json
, add the --port
option to ng serve
and use npm start
to start the server.
"scripts": {
"ng": "ng",
"start": "ng serve --port 8000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
add a comment |
As far as Angular CLI: 7.1.4, there are two common ways to achieve changing the default port.
No. 1
In the angular.json
, add the --port
option to serve
part and use ng serve
to start the server.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 1337
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
}
}
},
No. 2
In the package.json
, add the --port
option to ng serve
and use npm start
to start the server.
"scripts": {
"ng": "ng",
"start": "ng serve --port 8000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
As far as Angular CLI: 7.1.4, there are two common ways to achieve changing the default port.
No. 1
In the angular.json
, add the --port
option to serve
part and use ng serve
to start the server.
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "demos:build",
"port": 1337
},
"configurations": {
"production": {
"browserTarget": "demos:build:production"
}
}
},
No. 2
In the package.json
, add the --port
option to ng serve
and use npm start
to start the server.
"scripts": {
"ng": "ng",
"start": "ng serve --port 8000",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
answered Jan 4 at 4:28
HearenHearen
2,94511530
2,94511530
add a comment |
add a comment |
The answer provided by elwyn is correct. But you should also update protractor config for e2e.
In angular.json,
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 9000,
"browserTarget": "app:build"
}
}
In e2e/protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:9000/'
}
add a comment |
The answer provided by elwyn is correct. But you should also update protractor config for e2e.
In angular.json,
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 9000,
"browserTarget": "app:build"
}
}
In e2e/protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:9000/'
}
add a comment |
The answer provided by elwyn is correct. But you should also update protractor config for e2e.
In angular.json,
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 9000,
"browserTarget": "app:build"
}
}
In e2e/protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:9000/'
}
The answer provided by elwyn is correct. But you should also update protractor config for e2e.
In angular.json,
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"port": 9000,
"browserTarget": "app:build"
}
}
In e2e/protractor.conf.js
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./src/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:9000/'
}
answered Mar 19 at 5:38
Prashanth SuriyanarayananPrashanth Suriyanarayanan
11.3k72347
11.3k72347
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37154813%2fangular-cli-server-how-to-specify-default-port%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown