Skip to content

Angular CLI

The Angular CLI (ng) is the official command-line tool for creating, developing, testing, and building Angular projects. It scaffolds new projects and components with consistent structure, wires up build tooling (via esbuild/Vite in modern Angular versions), and wraps common workflows β€” dev server, testing, linting β€” behind simple commands.

Terminal window
npm install -g @angular/cli # install the CLI globally
ng new my-app # scaffold a new project (prompts for options)
cd my-app
ng serve # start the dev server at localhost:4200 with live reload
ng generate component user-profile # or shorthand: ng g c user-profile
ng generate service auth # or: ng g s auth
ng build # production build, output to dist/
ng test # run unit tests
ng lint # run the linter

Manually creating component files by hand-copying an existing one β€” this is error-prone (mismatched selectors, stale imports, forgotten registration) compared to ng generate component, which creates all the right files with correct naming and wiring in one step.

Terminal window
# Error-prone: copy-paste an existing component and edit by hand
cp -r src/app/user-profile src/app/user-settings
# now manually fix: class name, selector, template filename references, tests...
# Reliable: let the CLI generate it correctly the first time
ng generate component user-settings
  1. What command creates a brand-new Angular project?

    Answerng new my-app
  2. What’s the shorthand for ng generate component?

    Answerng g c β€” e.g. ng g c user-profile.
  3. Why is ng generate generally preferred over manually copying an existing component’s files?

    AnswerIt reliably produces correctly-named, correctly-wired files (class name, selector, imports, test scaffold) in one step, avoiding the small mismatches that creep in from manual copy-paste.