Angular Get Started

The Angular CLI is the fastest, most reliable way to create, run, and build an Angular application from your terminal.

Installing the Angular CLI

The Angular CLI (Command Line Interface) is a Node.js package that scaffolds projects, generates code, runs a development server, and produces optimized production builds. It is installed once, globally, and then used from any project folder.

Install the CLI globally

// This is a terminal/CLI reference, not runnable Angular code — commented out
// so it compiles as a harmless no-op instead of a syntax error.
// npm install -g @angular/cli

// # Verify the installation
// ng version
Note: The CLI requires an active LTS or maintenance version of Node.js. Check the Angular documentation for the Node.js version required by the Angular release you plan to use.

Creating a New Project

The ng new command scaffolds a complete, ready-to-run application: folder structure, configuration files, a starter component, and a test setup. Modern Angular defaults to standalone components, so no root NgModule is generated unless you opt into one.

Scaffold a new application

// This is a terminal/CLI reference, not runnable Angular code — commented out
// so it compiles as a harmless no-op instead of a syntax error.
// ng new my-first-app

// # The CLI will prompt for options:
// # - Add Angular routing? (Yes)
// # - Which stylesheet format? (CSS)

// cd my-first-app
  • ng new <name> - creates a new application in a folder called <name>
  • ng serve - starts a local development server with live reload
  • ng generate component <name> - scaffolds a new component
  • ng build - produces an optimized, deployable build in the dist/ folder
  • ng test - runs unit tests with Karma or Jest, depending on configuration

Running the Development Server

Once inside the project folder, ng serve compiles the application and serves it locally, watching your files for changes. Any edit to a component, template, or stylesheet triggers an automatic rebuild and refreshes the browser.

Start the dev server

// This is a terminal/CLI reference, not runnable Angular code — commented out
// so it compiles as a harmless no-op instead of a syntax error.
// ng serve

// # Or specify a port and open the browser automatically
// ng serve --port 4300 --open
CommandWhat It Does
ng serveRuns the app locally at http://localhost:4200
ng buildCreates a production bundle in dist/
ng generate component <name>Creates a new component's files
ng add <package>Installs and configures an Angular library
Note: Use ng generate (or the shorthand ng g) for every new component, service, or directive. It creates consistently named files and wires up imports automatically, avoiding typos.
Note: ng serve is meant only for local development. It is not optimized and should never be used to host a production application - always deploy the output of ng build.

Exercise: Angular Get Started

What is the recommended way to create a new Angular project?