10

I have a little question about angular-cli.

Is it true that when I run ng serve I use the global installed angular-cli and when I run npm start the local one?

Dawid Dyrcz
  • 355
  • 1
  • 4
  • 10
  • 1
    Where are you getting this information? I am inclined to believe this is false. When I run `npm start` on my cli project, it just runs `ng serve`. – Bean0341 Feb 17 '17 at 20:10
  • 1
    I asked this question because i have globally installed angular-cli with version 1.0.0-beta.26 and locally the latest with version 1.0.0-beta.32.3. And when i run ng serve i'm getting error, and when run npm start everything is ok – Dawid Dyrcz Feb 17 '17 at 20:24
  • Another thing that convinces me that this is true. I have just uninstall globall angular-cli with `npm uninstall -g angular-cli @angular/cli` and now when i try run `ng serve`, it's says that ng in not recognized whereas `npm start` still works – Dawid Dyrcz Feb 18 '17 at 13:15
  • Here's [Another answer](https://stackoverflow.com/questions/40190538/when-to-use-npm-start-and-when-to-use-ng-serve)! you can refer to – Selvakumar Jul 21 '17 at 11:15
  • Possible duplicate of [When to use 'npm start' and when to use 'ng serve'?](https://stackoverflow.com/questions/40190538/when-to-use-npm-start-and-when-to-use-ng-serve) – andolsi zied Oct 29 '17 at 12:16

4 Answers4

5

Command will decide by package.json . ng serve / npm start is used based on package.json can change form there. if ng serve is not working can use npm start to run server.

ng server :

"scripts": { "ng": "ng", "start": "ng serve", "test": "ng test",....... }

Vicky
  • 602
  • 5
  • 16
5

When you run the npm start internally it will call whatever command is written inside the start in the package.json.

"scripts": {
  "start": "ng serve"
}

it will run the ng serve

For more details, check When to use 'npm start' and when to use 'ng serve'?

Reven
  • 776
  • 2
  • 8
  • 23
Er. Bahuguna Goyal
  • 192
  • 1
  • 3
  • 10
3

Yes it is true.

Let's say your global Angular CLI version is 2 and you just cloned and installed a project from github that is created with Angular CLI version 1. If you run ng serve it will execute using version 2 (which is your global cli), if you run npm run start it will use the script in node_modules/.bin folder (which is local to your project and which is the right one for the job).

yusuf tezel
  • 1,232
  • 13
  • 18
0

Yes. It is true. ng serve runs the app on angular global cli on the current version of the installed angular version while npm run start runs it on the version of that particular angular application cloned version from the node-module.