Angular Setup with the CLI

The Angular CLI scaffolds, runs, builds, and generates code for your project. It's central to the Angular workflow β€” you'll use it constantly.

Create and run

bash
npm install -g @angular/cli
ng new my-app
cd my-app
ng serve

ng serve starts a dev server at http://localhost:4200 with live reload on every change.

Generating code

The CLI generates components, services, and more β€” with the right files, boilerplate, and naming β€” so you don't create them by hand.

bash
ng generate component product     # or: ng g c product
ng g service data                 # a service
ng g guard auth                   # a route guard
ng g pipe currency-format         # a pipe

Project structure

project
my-app/
β”œβ”€ src/
β”‚  β”œβ”€ main.ts              # bootstraps the app
β”‚  β”œβ”€ app/
β”‚  β”‚  β”œβ”€ app.component.ts  # root component
β”‚  β”‚  β”œβ”€ app.config.ts     # app-wide providers
β”‚  β”‚  └─ app.routes.ts     # route definitions
β”‚  └─ index.html
└─ angular.json            # CLI/build config

Common commands

CommandDoes
ng serverun the dev server
ng buildproduction build
ng testrun unit tests
ng generatescaffold code
Tip: Let the CLI generate everything β€” components, services, guards, pipes. It follows Angular conventions and wires files up correctly, saving time and keeping the project consistent.
Free preview. Sign in and subscribe to unlock all 809 lessons across 25 courses.
Angular Setup with the CLI β€” Angular | Full Stack Learning Simplified