Angular CLI Commands


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

Angular Command

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

Angular Command

3. Node Version

This command is used to get node version.

node -v

Output

Angular Command

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

Angular Command

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.

  • ng serve
  • npm start
  • ng serve --force

10. Generate Command

These generate commands use to create new directive, component, module, service, class, interface, pipe etc. o i have grouped all these command as following:

  1. Directive Command

    This command is used to create directive in an angular application. It has following Syntax:
    ng generate directive directive-name
    ng g d directive-name
  2. Service Command

    This command is used to create Service in an angular application. It has following Syntax:
    ng generate service service-name
    ng g s service-name
  3. Class Command

    This command is used to create Class in an angular application. It has following Syntax:
    ng generate class class-name
    ng g cl class-name
  4. Interface Command

    This command is used to create Interface in an angular application. It has following Syntax:
    ng generate interface interface-name
    ng g i interface-name
  5. Pipe Command

    This command is used to create Pipe in an angular application. It has following Syntax:
    ng generate pipe pipe-name
    ng g p pipe-name
  6. Enum Command

    This command is used to create Enum in an angular application. It has following Syntax:
    ng generate enum enum-name
    ng g e enum-name
  7. Module Command

    This command is used to create Module in an angular application. It has following Syntax:
    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
  8. Module with Routing

    This command is used to create Module with Routing in an angular application. It has following Syntax:
    ng g m module-name --routing
  9. Guard to the Route

    This command is used to create Guard to the Route in an angular application. It has following Syntax:
    ng g guard guard-name

11. Installed and Uninstall Command

  1. To uninstall Angular CLI
    npm uninstall --save-dev @angular/cli
    npm uninstall -g angular-cli @angular/cli
  2. To install the latest version of Angular CLI
    npm install --save-dev @angular/cli@latest
  3. To install TypeScript latest version
    npm install -g typescript@latest
  4. To install Jasmine/Karma latest version
    npm install -g karma-jasmine@latest
  5. To install TypeScript specific version
    npm install typescript@version-number
  6. To install Jasmine specific version
    npm install -g jasmine@version-number
  7. To install Karma specific version
    npm install -g karma@version-number

12. To update Angular CLI

ng update @angular/cli
ng update @angular/core

Prev Next