Angular CLI

The Angular CLI (Command Line Interface) is a tool that allows you to create, build, and deploy Angular applications quickly and easily. It provides a set of commands that you can use in your terminal to create and manage your Angular projects.

To install the Angular CLI, open your terminal and run the following command:

npm install -g @angular/cli 

This installs the Angular CLI globally on your computer, allowing you to use it in any project. npm is the package manager for JavaScript and the -g flag installs the package globally so that it can be used in any project on your machine.

Once the Angular CLI is installed, you can create a new Angular project by running the following command:

ng new my-project 

This creates a new directory called "my-project" with the necessary files and dependencies for an Angular app. The Angular CLI sets up the basic structure of an Angular app, including the root module (AppModule), the root component (AppComponent), and the necessary configuration files.

You can also use the Angular CLI to generate new components, directives, pipes, and services for your Angular app by running the following commands:


# For Generating new Component
ng generate component my-component 

# For Generating new Directives
ng generate directive my-directive 

#For Generating Pipe
ng generate pipe my-pipe 

#For Generating Service
ng generate service my-service 

These commands create the necessary files for the specified type of entity (component, directive, pipe, or service) and add them to the appropriate module.

The Angular CLI also provides commands for building and serving your Angular app. To build the app for production, you can run the following command:

ng build --prod 

This compiles the app and creates a production build in the dist directory.

To serve the app locally for development, you can run the following command:

ng serve 

This compiles and serves the app, and it will be available at http://localhost:4200/. The development server will also automatically reload the app whenever you make changes to the code.

The Angular CLI also provides commands for running tests and creating production builds. To run tests, you can use the following command:

ng test 

This runs the unit tests for the app using the Karma test runner.

To see a full list of available commands, you can run the following command:

ng help

Additional Detail's

  • The Angular CLI is built on top of the Angular framework, and it uses the Angular schematics library to generate code and files for different parts of an Angular app.

  • The Angular CLI uses a configuration file called angular.json to store project-specific settings, such as the root module, the root component, the project's dependencies, and the build and test configurations.

  • You can customize the build and test configurations in the angular.json file by adding additional options to the "architect" object. For example, you can specify the type of build (development, production, etc.), the output directory, the test runner, and other options.

  • The Angular CLI provides a number of options that you can use to customize the behavior of the commands. For example, you can use the --dry-run option to preview the changes that a command would make without actually applying them. You can also use the --help option to see a list of available options for a particular command.

  • In addition to the commands provided by the Angular CLI, you can also create your own custom commands using the Angular schematics library. This allows you to automate repetitive tasks or create custom code generation scripts.