8

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
  • 325
  • 1
  • 3
  • 9
  • 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

3 Answers3

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
  • 727
  • 2
  • 8
  • 22
Er. Bahuguna Goyal
  • 172
  • 1
  • 3
  • 10
4

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
  • 572
  • 4
  • 15
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,152
  • 11
  • 18