Skip to content

Angular CLI

Angular CLI (ng) is a command-line interface for Angular. It allows you to create, build, test, and run Angular applications from the command line. Let’s dive into the essential aspects of Angular CLI for programmers.

To install the Angular CLI, run the following command:

Terminal window
npm install -g @angular/cli

To create a new Angular project, run the following command:

Terminal window
ng new my-app

This will create a new Angular project named my-app in the current directory. You can also specify the directory name as follows:

Terminal window
ng new my-app --directory my-dir

To generate a new component, run the following command:

Terminal window
ng generate component my-component

This will create a new component named my-component in the src/app directory. You can also specify the directory name as follows:

Terminal window
ng generate component my-component --directory my-dir

To update Angular in an existing project, run the following command:

Terminal window
ng update @angular/cli @angular/core

To update the Angular CLI, run the following command:

Terminal window
npm install -g @angular/cli@latest

To run the application, run the following command:

Terminal window
ng serve

This will start the application on port 4200. You can also specify the port number as follows:

Terminal window
ng serve --port 3000

To build the application, run the following command:

Terminal window
ng build

To test the application, run the following command:

Terminal window
ng test

This will run all the tests in the src/app directory.

To debug the application, run the following command:

Terminal window
ng serve --inspect

This will start the application in debug mode. You can then attach a debugger to the application.