Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - ng serve vs npm start

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?

like image 636
Dawid Dyrcz Avatar asked Feb 17 '17 19:02

Dawid Dyrcz


People also ask

What is the difference between NPM start and Ng serve?

Then npm start will run ng serve. For a project that's using the CLI, you will usually use ng serve. In other cases you may want to use npm start. Here the detailed explanation: Will serve a project that is 'Angular CLI aware', i.e. a project that has been created using the Angular CLI, particularly using:

Is Ng serve the same as angular-CLI start?

Yeah, but angular-cli creates the start command upon initialization so if he hasn't modified it should be the same command. Note: Using npm start is better. In order to use ng serve you need to install angular cli globally or reference it from the node modules bin. This answer is misleading, look at my answer.

How do I serve a project using the angular CLI?

For a project that's using the CLI, you will usually use ng serve. In other cases you may want to use npm start. Here the detailed explanation: Will serve a project that is 'Angular CLI aware', i.e. a project that has been created using the Angular CLI, particularly using:

What is the best way to start an angular build server?

Finally run usual npm start command to start build server. The best answer is great, short and on point, but I would like to put my pennyworth. Basically npm start and ng serve can be used interchangeably in Angular projects as long as you do not want the command to do additional stuff.


3 Answers

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'?

like image 123
Er. Bahuguna Goyal Avatar answered Oct 27 '22 06:10

Er. Bahuguna Goyal


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",....... }

like image 40
Vicky Avatar answered Oct 27 '22 05:10

Vicky


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).

like image 36
yusuf tezel Avatar answered Oct 27 '22 06:10

yusuf tezel