Angular Get Started
To build Angular apps on your own computer you need two things: Node.js and the Angular CLI. The CLI (command-line interface) creates projects, generates code, runs a development server, executes tests and produces optimized builds.
Step 1: Install Node.js
Download the current LTS release from the official Node.js website. Angular supports the active and maintenance LTS versions of Node. Check what you have:
node --version
npm --versionv22.12.0
10.9.0
Step 2: Install the Angular CLI
The CLI is an npm package called @angular/cli. Install it globally so the ng command is available everywhere:
npm install -g @angular/cli
ng versionadded 268 packages in 14s
Angular CLI: 20.3.4
Node: 22.12.0
Package Manager: npm 10.9.0
OS: linux x64
Tip: If you prefer not to install anything globally, prefix every command with
npx, for examplenpx @angular/cli new my-app.
Step 3: Create a project
ng new asks a few questions and then creates a ready-to-run workspace:
ng new task-board✔ Which stylesheet format would you like to use? CSS
✔ Do you want to enable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering)? No
✔ Do you want to create a 'zoneless' application without zone.js? Yes
CREATE task-board/angular.json (2061 bytes)
CREATE task-board/package.json (1037 bytes)
CREATE task-board/README.md (1475 bytes)
CREATE task-board/tsconfig.json (1001 bytes)
CREATE task-board/src/index.html (295 bytes)
CREATE task-board/src/main.ts (222 bytes)
CREATE task-board/src/styles.css (80 bytes)
CREATE task-board/src/app/app.config.ts (412 bytes)
CREATE task-board/src/app/app.routes.ts (77 bytes)
CREATE task-board/src/app/app.ts (298 bytes)
CREATE task-board/src/app/app.html (512 bytes)
CREATE task-board/src/app/app.css (0 bytes)
CREATE task-board/src/app/app.spec.ts (684 bytes)
✔ Packages installed successfully.
Successfully initialized git.
Useful flags when you want to skip the questions:
| Flag | Effect |
|---|---|
--style=scss |
Use SCSS instead of CSS |
--ssr=false |
Do not add server-side rendering |
--routing |
Add a routes file (the default in new versions) |
--skip-tests |
Do not generate .spec.ts test files |
--defaults |
Accept the default answer for every prompt |
Step 4: Run the development server
Move into the folder and start the dev server. It compiles the app, serves it on port 4200 and rebuilds automatically every time you save a file:
cd task-board
ng serve --openInitial chunk files | Names | Raw size
main.js | main | 92.41 kB |
styles.css | styles | 95 bytes |
| Initial total | 92.50 kB
Application bundle generation complete. [1.204 seconds]
Watch mode enabled. Watching for file changes...
➜ Local: http://localhost:4200/
➜ press h + enter to show help
--open (short: -o) launches your browser. Open src/app/app.html, change some text and save — the page refreshes on its own.
Step 5: Generate code
Typing component files by hand gets tedious. ng generate (short: ng g) creates them with the right names and boilerplate:
ng generate component task-card
ng g service task-storeCREATE src/app/task-card/task-card.css (0 bytes)
CREATE src/app/task-card/task-card.html (25 bytes)
CREATE src/app/task-card/task-card.spec.ts (584 bytes)
CREATE src/app/task-card/task-card.ts (210 bytes)
CREATE src/app/task-store.spec.ts (368 bytes)
CREATE src/app/task-store.ts (138 bytes)
Note: Recent Angular versions follow a simplified style guide: files are named
task-card.tsand the class isTaskCard. Older projects (and many tutorials) usetask-card.component.tsandTaskCardComponent. Both work the same way.
The CLI commands you'll use most
| Command | Purpose |
|---|---|
ng new <name> |
Create a new workspace |
ng serve |
Dev server with live reload |
ng generate <type> <name> |
Create components, services, pipes, guards… |
ng test |
Run unit tests |
ng build |
Create an optimized production build in dist/ |
ng add <package> |
Install a library and run its setup |
ng update |
Upgrade Angular and apply automatic migrations |
Test yourself
Which npm package provides the ng command?
- @angular/core
- @angular/cli
- angular
- ng-tools
On which port does ng serve run by default?
- 3000
- 8080
- 4200
- 5173
What does ng g c profile do?
- Deletes the profile component
- Generates a component named profile
- Compiles the profile folder
- Creates a git commit