Install the Angular CLI & Create a Project
Angular apps are created, run, tested and built with the Angular CLI, a command-line tool called ng. The CLI writes the starting files for you, runs a development server that reloads the page when you save, and produces optimised files for production.
In this lesson you will install Node.js and the CLI, create your first Angular 22 project, run it in the browser and learn the CLI commands you will use every day.
Step 1: install Node.js
The Angular CLI runs on Node.js, a program that runs JavaScript outside the browser. It also brings npm, the package manager that downloads Angular and its tools.
Angular 22 needs Node.js 22.22.3 or newer in the 22 line, 24.15.0 or newer in the 24 line, or Node.js 26 and later. The simplest choice is the current LTS (long-term support) release, Node.js 26, from the official site nodejs.org. After installing, open a new terminal and check the versions:
node -v
npm -vv26.13.0 11.20.0
Your exact numbers may be higher. If node -v prints something older, the CLI will refuse to start with a message like this one:
Node.js version v22.14.0 detected. The Angular CLI requires a minimum Node.js version of v22.22.3 or v24.15.0 or v26.0.0.
Step 2: install the Angular CLI
Install the CLI once, globally (-g), so the ng command works in any folder:
npm install -g @angular/cli
ng versionng version prints a banner and a table with the CLI version (22.x), your Node.js version and your operating system.
Step 3: create a project
Go to the folder where you keep your code and run ng new with a project name. Use lowercase letters and hyphens:
cd D:\projects
ng new canteenThe CLI asks a couple of questions:
- Which stylesheet system would you like to use? Choose CSS for now. Sass (SCSS), Less and Tailwind CSS are also offered.
- Do you want to enable Server-Side Rendering (SSR) and Static Site Generation? Choose No for now. You will learn SSR later in SSR & Hydration.
If it asks anything else, the default answer is fine. The CLI then creates a canteen folder, writes the starting files and runs npm install to download Angular. This can take a minute or two. You can also answer the questions with options, which is handy in scripts:
ng new canteen --style=css --ssr=falseA new Angular 22 project is standalone (no NgModule), zoneless (no zone.js), uses TypeScript 6.0 and uses Vitest for unit tests.
Step 4: run the development server
Move into the project and start the development server:
cd canteen
ng serveInitial chunk files | Names | Raw size main.js | main | 48.85 kB | styles.css | styles | 95 bytes | Application bundle generation complete. [9.138 seconds] Watch mode enabled. Watching for file changes... ➜ Local: http://localhost:4200/
Open http://localhost:4200/ in your browser to see the welcome page. Leave the terminal running. When you edit and save a file, the CLI rebuilds and the browser updates on its own. Press Ctrl+C in the terminal to stop the server. npm start does the same as ng serve, and ng serve --open also opens the browser for you.
Everyday CLI commands
The ng generate command (short form ng g) creates new files that follow the official style guide:
ng generate component menu-card
ng g service cart
ng g pipe rupee
ng g directive highlightCREATE src/app/menu-card/menu-card.spec.ts (569 bytes) CREATE src/app/menu-card/menu-card.ts (206 bytes) CREATE src/app/menu-card/menu-card.css (0 bytes) CREATE src/app/menu-card/menu-card.html (25 bytes) CREATE src/app/cart.spec.ts (325 bytes) CREATE src/app/cart.ts (80 bytes)
Notice the file names: since Angular 20, the CLI writes menu-card.ts, not menu-card.component.ts, and the class is called MenuCard, not MenuCardComponent. You will meet the longer names in older projects.
| Command | What it does |
|---|---|
ng new <name> | Creates a new workspace and app |
ng serve | Runs the development server with live reload |
ng generate <type> <name> | Creates a component, service, pipe, directive, guard and more |
ng build | Builds optimised files for production into dist/ |
ng test | Runs unit tests with Vitest |
ng add <package> | Installs a library and runs its setup, for example ng add @angular/ssr |
ng update | Updates Angular to a newer version and migrates your code |
When you are ready to publish, run ng build. The output goes to dist/canteen/browser, a folder of plain HTML, CSS and JavaScript files that any static web host can serve.
Set up your editor
Use Visual Studio Code. The new project includes a recommendation for the Angular Language Service extension, so VS Code offers to install it when you open the folder. It gives you autocomplete, error checking and "go to definition" inside templates, which saves a lot of time.
Common mistakes
- Old Node.js version. The CLI stops with "requires a minimum Node.js version". Install the current LTS and open a new terminal.
- Running
ng servein the wrong folder. You must be inside the project folder (the one withangular.json), or you get "This command is not available when running the Angular CLI outside a workspace". - Port already in use. If another server uses port 4200, run
ng serve --port 4300. - Spaces or capitals in the project name. Use names like
canteenorexam-portal.
Key points
- Install Node.js (26 LTS is a good choice), then the CLI with
npm install -g @angular/cli. ng new canteencreates a standalone, zoneless Angular 22 project with TypeScript 6.0 and Vitest.ng serveruns the app athttp://localhost:4200/and reloads when you save.ng generatecreates components, services, pipes and more, using short file names likemenu-card.ts.ng buildwrites production files todist/<project>/browser.
Exercise
Create a project called college-fest with SCSS styles and no SSR, using options instead of answering prompts. Start the development server on port 4300. Then generate a component called event-list and a service called registration, and list the files the CLI created.
Show solution
ng new college-fest --style=scss --ssr=false
cd college-fest
ng serve --port 4300In a second terminal, inside college-fest:
ng g component event-list
ng g service registrationThe component command creates event-list.ts, event-list.html, event-list.scss and event-list.spec.ts in src/app/event-list/. The service command creates registration.ts and registration.spec.ts in src/app/.
Quick Quiz
1. Which command creates a new Angular workspace and app?
ng new creates the folder, writes the starting files and installs packages.
2. What address does ng serve use by default?
The Angular development server listens on port 4200 unless you pass --port.
3. What file name does Angular 22 give a generated component called menu-card?
Since Angular 20 the CLI uses the shorter style-guide names without the .component suffix.
4. Which test runner do new Angular 22 projects use by default?
Vitest is the default unit test runner for new projects; Karma is still available as an option.
Learn Angular with a mentor
Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
