Setup and the Angular CLI
Installing Angular and Using the CLI
The Angular CLI (@angular/cli) is your primary tool for scaffolding, generating, building, testing, and serving Angular applications. Install it globally with npm or pnpm, then use ng new to create a project.
npm install -g @angular/cli
# Create a new Angular project
ng new my-app --standalone --routing --style=scss
cd my-app
ng serveThe --standalone flag generates a project using standalone components — the modern Angular approach. You no longer need NgModules for small to medium-sized apps.
Key CLI Commands
ng new <name>— scaffold a new workspace and applicationng serve— run the dev server with hot module replacementng generate component <name>(orng g c) — create a componentng generate service <name>— create a serviceng build --configuration production— compile for productionng test— run unit tests via Karma/Jestng lint— lint the project
Project Structure
A freshly generated Angular project includes src/app/ for your application code, src/main.ts as the bootstrap entry point, angular.json for workspace configuration, and tsconfig.json for TypeScript settings. The CLI keeps these files in sync as you generate more pieces.
# Generate a feature component
ng g c features/dashboard --standalone
# Generate a service
ng g s services/user
# Generate a route guard
ng g guard guards/authCPCODELAB students: run ng new with --standalone and --style=scss for all course projects. This matches modern Angular practices covered throughout the curriculum.