Angular CLI commands
Angular CLI is a Command Line Interface tool which is used to writing command for initialize, develop, scaffold, and maintain Angular applications. CLI makes Angular development workflow much easier and faster . We can run these commands directly from command prompt is called angular console or angular terminal.
Here, You will see commonly used commands in an Angular project.
1. To install Angular CLI
This command is used to check version.
ng version
Output
This command is used when CLI is not installed, then use the below command to install it. If install will display version of node and npm.
npm install -g @angular/cli@^8.0.0
2. NPM Version
This command is used to get npm version.
npm -v
Output
3. Node Version
This command is used to get node version.
node -v
Output
4. Jasmine version
This command is used to get Jasmine version.
jasmine -v
5. Karma version
This command is used to get Karma version.
karma --version
6. Angular CLI Next Version
This command is used to install next version of Angular CLI.
npm install @angular/cli@next
7. Help Command
This command is used to get lists of available commands in terminal.
Output
8. New Command
This commang is used to create new project.
ng new project-name
To skip external dependencies while creating a new project,
ng new project-name --skip-install
9. To run the Angular project
These command is used to run the angular application.
These generate commands use to create new directive, component, module, service, class, interface, pipe etc. o i have grouped all these command as following:
ng generate directive directive-name
ng g d directive-name
ng generate service service-name
ng g s service-name
ng generate class class-name
ng g cl class-name
ng generate interface interface-name
ng g i interface-name
ng generate pipe pipe-name
ng g p pipe-name
ng generate enum enum-name
ng g e enum-name
ng generate module module-name
ng g m module-name
To create a spec file for the module:
ng g m module-name --spec true -d
ng g m module-name --routing
ng g guard guard-name
11. Installed and Uninstall Command
npm uninstall --save-dev @angular/cli
npm uninstall -g angular-cli @angular/cli
npm install --save-dev @angular/cli@latest
npm install -g typescript@latest
npm install -g karma-jasmine@latest
npm install typescript@version-number
npm install -g jasmine@version-number
npm install -g karma@version-number
12. To update Angular CLI
ng update @angular/cli
ng update @angular/core