Installing Angular (Angular CLI)
Scaffold a new Angular project using the Angular CLI and understand every setup prompt it asks.
Installing the Angular CLI
The Angular CLI is a command-line tool for generating, building, testing, and running Angular projects. Install it globally once, and it's available for every project afterward.
npm install -g @angular/cliCreating a Project
ng new my-appcd my-appng serveUnderstanding the Setup Prompts
| Prompt | Recommended Answer | Why |
|---|---|---|
| Which stylesheet format? | CSS | Simplest choice for this course; Sass/Less work identically if you prefer them. |
| Enable Server-Side Rendering (SSR)? | No (for now) | SSR with Angular Universal is covered in its own dedicated lesson later. |
| Would you like to add Angular routing? | Yes | Sets up the Angular Router from the start — this course uses it from early on. |
Running the Dev Server
ng serve# Local: http://localhost:4200/Click Run to see what this code prints.
Edit a component file and save — the browser automatically reloads to reflect your change, thanks to the Angular CLI's built-in dev server.
Available CLI Commands
- ng serve — starts the development server with live reload.
- ng build — creates an optimized production build.
- ng generate component my-component — scaffolds a new component with all its files.
- ng test — runs the project's unit tests.
Common Beginner Mistakes
Without a global install, run commands with npx ng serve instead of ng serve, or install globally as shown above to use ng directly.
That folder is generated output from ng build — any edits there are overwritten on the next build.
FAQs
Port 4200 by default — pass --port to use a different one.
Yes — ng generate and ng add can retrofit many features into an existing project, not just at creation time.
Summary
You now have a running Angular project, scaffolded and managed through the Angular CLI. Next, you'll take a tour of the folders and files it generated.