CPCODELAB
Angular

Setup and the Angular CLI

10 min read

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.

bash
npm install -g @angular/cli

# Create a new Angular project
ng new my-app --standalone --routing --style=scss

cd my-app
ng serve

The --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

  1. ng new <name> — scaffold a new workspace and application
  2. ng serve — run the dev server with hot module replacement
  3. ng generate component <name> (or ng g c) — create a component
  4. ng generate service <name> — create a service
  5. ng build --configuration production — compile for production
  6. ng test — run unit tests via Karma/Jest
  7. ng 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.

bash
# 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/auth

CPCODELAB students: run ng new with --standalone and --style=scss for all course projects. This matches modern Angular practices covered throughout the curriculum.

Ready to test yourself?
Practice Angular— quiz & coding exercises