Angular - CLI Commands



Angular CLI, a short form of Angular Command Line Interface, is a tool used for creating and managing Angular applications. It is built on top of Node.js and installed from NPM. It provides a set of commands to generate, build, test, and deploy Angular projects.

With the help of Angular CLI, developers can quickly set up a new project, add components, services, directives and any other features. This tutorial explains all the Angular CLI commands in detail.

Node.js is a runtime environment that allows you to run JavaScript code outside of a web browser. NPM (Node Package Manager) is a tool that comes with Node.js and helps you manage packages and dependencies for your projects.

Verify CLI

Before moving to Angular CLI commands, we have to ensure that Angular CLI is installed on your machine. If it is installed, you can verify it by using the below command −

ng version

After running this command, you may see the following response −

CLI

If CLI is not installed, then use the below command to install it −

npm install -g @angular/cli

For MAC or Linux operating systems, use the below command −

sudo npm install -g @angular/cli

Angular CLI Commands

There are a number of CLI commands used to manage Angular applications and all of them start with the prefix ng, which stands for Angular. Some of the Angular CLI are listed in the table given below −

SNo. Commands & Descriptions

1.

ng new <project-name>

To create an Angular application.

2.

ng generate component <component-name>

To create a component in Angular.

3.

ng generate class <class-name>

To create a new class in Angular.

4.

ng generate pipe <pipe-name>

It creates a custom pipe in Angular.

5.

ng generate directive <directive-name>

It creates a new directive in Angular.

6.

ng generate module <module-name>

To create a new module in Angular.

7.

ng generate interface <interface-name>

It is used to create an interface in Angular.

8.

ng generate webWorker <webWorker-name>

It creates a new web worker.

9.

ng generate service <service-name>

It creates a new service.

10.

ng generate enum <enum-name>

It generates a new enum.

11.

ng add [name]

It is used to add support for an external library to your project.

12.

ng build

It is used to compile or build your angular app.

13.

ng config

It is used to retrieve or set Angular configuration values in the angular.json file for the workspace.

14.

ng config

It is used to retrieve or set Angular configuration values in the angular.json file for the workspace.

15.

ng doc <keyword>

This command opens the official Angular documentation in a browser, and searches for a given keyword.

16.

ng version

Shows the Angular CLI version.

17.

ng update

Updates your application and its dependencies.

18.

ng test

Runs unit tests in a project.

19.

ng serve

It is used to build and serve your app. Also, rebuilds on file changes.

20.

ng help

It lists out available commands and their short descriptions.

21.

ng e2e <project> [options]

It build and serves an Angular app, and then runs end-to-end tests using Protractor.

22.

ng deploy

Deploy your Angular application to a specific hosting service, such as Firebase or GitHub Pages.

23.

ng cache clean

Deletes the disk cache.

24.

ng cache info

Displays the disk cache configuration and statistics.

25.

ng analytics disable

It will disable the analytics gathering and reporting for the user.

26.

ng analytics info

Displays the collected analytics.

Advertisements