Where can I get an Angular CLI?
npm install -g @angular/cli
A small notes about difference between installation Angular CLI using flag
-g flag or without it. When you install Node Package in using global mode (
-g) it means that it's installing in a root folder
urs/local/lib/node_modules on MacOS by default. And every time when you type
ng new NodeJS will search application first in the
node_modules directory in your project then in the global scope.
If you install Angular CLI or other libraries using global flag you will always have this library in the global scope that means that you don't have to install Angular CLI on every new project.
Am I have to install Angular CLI with a global scope always? Usually the answer is Yes, if you are planing to make more than one project on Angular. But be aware that in this situation you have to update Angular CLI by yourself, so don't forget to do it sometimes with this commands:
npm uninstall -g @angular/cli npm cache clean npm install -g @angular/cli@latest
How to create a new Angular application?
Move to the folder where you want to create your Angular application using bash terminal or your IDE terminal
ng new stock-api cd stock-api ng serve
My congratulations you just have build a new Angular application!
Sometimes in your Angular project you need to specify which CSS preprocessor you want to use
--style parameter which can take following arguments:
--style=css --style=scss --style=less --style=sass --style=styl
Default value is
CSS but you can choose everyone you wish, example of usage:
ng new stock-api --style=sass
Another interesting parameter is
--inline-template which can specify what type of templates do you want to use, default value is
false which means that you template will be on the separate file.
For additional information about new Angular application parameters visit official wiki page.
If you use Linux or MacOS operation system, make sure that you install Angular CLI with superuser rights, to make it use following code
sudo npm install -g @angular/cli
You also might come across with problem when update to Angular CLI 6.0 from lower versions,
Local workspace file ('angular.json') could not be found.
Use following command to create that file with all dependencies automatically:
ng update @angular/cli --migrate-only --from=1.7.4