Tags:  npmangular
Source:  Twitter logo

I just ended the tutorial of Angular 2 and I can't find a way to change the localhost port from 3000 to 8000. In my package.json file there's the line "start": "concurrent \"npm run tsc:w\" \"npm run lite\" " that I believe is related but I'm not sure.

You can change it inside bs-config.json file as mentioned in the docs https://github.com/johnpapa/lite-server#custom-configuration

For example,

  "port": 8000,
  "files": ["./src/**/*.{html,htm,css,js}"],
  "server": { "baseDir": "./src" }
22 users liked answer #0dislike answer #022
Kalman profile pic

Using Angular 4 and the cli that came with it I was able to start the server with $npm start -- --port 8000. That worked ok: ** NG Live Development Server is listening on localhost:8000, open your browser on http://localhost:8000 **

Got the tip from Here

14 users liked answer #1dislike answer #114
Hodglem profile pic

1-> Using File Default Config- Angular-cli comes from the ember-cli project. To run the application on specific port, create an .ember-cli file in the project root. Add your JSON config in there:

{ "port": 1337 }

2->Using Command Line Tool Run this command in Angular-Cli

ng serve --port 1234

To change the port number permanently:



Search for var defaultPort = process.env.PORT || 4200; (change 4200 to anything else you want).

7 users liked answer #2dislike answer #27
Akshay Bohra profile pic
Akshay Bohra

In package.json set the following command (example for running on port 82)

"start": "set PORT=82 && ng serve --ec=true"

then npm start

3 users liked answer #3dislike answer #33
Alex Pandrea profile pic
Alex Pandrea

You can change it in the webpack.dev.js file in config folder.

0 users liked answer #4dislike answer #40
user7538631 profile pic

If want to change port number in angular 2 or 4 we just need to open .angular-cli.json file and we need to keep the code as like below

"defaults": {
    "styleExt": "css",
    "component": {}
"serve": {
      "port": 8080

0 users liked answer #5dislike answer #50
Rajesh Kumar Kanumetta profile pic
Rajesh Kumar Kanumetta

If you don't have bs-config.json, you can change the port inside the lite-server module. Go to node_modules/lite-server/lib/config-defaults.js in your project, then add the port in "modules.export" like this.

module.export {
    port :8000, // to any available port

Then you can restart the server.

0 users liked answer #6dislike answer #60
Divya N profile pic
Divya N

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).