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?
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:
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.
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:
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.
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'?
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",....... }
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With