NexusCS

Angular CLI

JavaScript libraries
Angular CLI (@angular/cli) is the official command-line tool for creating, developing, building, and testing Angular applications.
featured

Getting started

Installation

npm install -g @angular/cli

Verify installation:

ng version

Create New Project

ng new my-app

With options:

ng new my-app --routing --style=scss
ng new my-app --minimal --skip-tests
ng new my-app --standalone --ssr
ng new my-app --package-manager=pnpm

Quick Start

ng new my-app
cd my-app
ng serve --open

Opens browser at localhost:4200

Project Creation

ng new Options

Option Default Description
--routing prompt Enable routing
--style css css/scss/sass/less
--prefix app Selector prefix
--skip-tests false Skip test files
--skip-install false Skip npm install
--standalone true Standalone app
--ssr prompt Enable SSR/SSG
--test-runner vitest vitest or karma
--package-manager npm npm/yarn/pnpm/bun

Examples

Minimal setup:

ng new my-app --minimal --skip-tests

With routing and SCSS:

ng new my-app --routing --style=scss

SSR with pnpm:

ng new my-app --ssr --package-manager=pnpm

Standalone with no SSR:

ng new my-app --standalone --ssr=false

Generation (ng g)

Component

ng g component my-component
ng g c my-component

With options:

ng g c my-component --standalone
ng g c my-component --inline-template
ng g c my-component --flat --skip-tests
ng g c my-component --style=scss

Service

ng g service my-service
ng g s my-service

With path:

ng g s services/my-service

Module

ng g module my-module
ng g m my-module

With routing:

ng g m my-module --routing

Other Generators

ng g directive my-directive    # ng g d
ng g pipe my-pipe              # ng g p
ng g guard my-guard            # ng g g
ng g interceptor my-interceptor
ng g interface my-interface
ng g class my-class
ng g enum my-enum
ng g resolver my-resolver
ng g library my-lib
ng g application my-app

Component Options

Common Flags

Option Alias Default Description
--standalone true Standalone component
--inline-template -t false Inline template
--inline-style -s false Inline styles
--skip-tests false Skip spec file
--flat false No subfolder
--export false Export from module
--style css Stylesheet type
--change-detection -c Default CD strategy

Examples

Inline component:

ng g c my-component -t -s --flat

No tests:

ng g c my-component --skip-tests

OnPush change detection:

ng g c my-component --change-detection=OnPush

Development Server

ng serve

Start dev server:

ng serve
ng serve --open

Aliases: ng dev, ng s

Server Options

Option Alias Default Description
--port 4200 Listen port
--host localhost Listen host
--open -o false Open browser
--ssl false Use HTTPS
--live-reload true Auto reload
--hmr (live-reload) Hot module replace
--proxy-config Proxy config file

Examples

Custom port:

ng serve --port 8080

External access:

ng serve --host 0.0.0.0

HTTPS:

ng serve --ssl

With proxy:

ng serve --proxy-config proxy.conf.json

Build

ng build

Production build:

ng build

Alias: ng b

Build Options

Option Alias Default Description
--configuration -c production Build config
--output-path dist/<name> Output dir
--optimization true (prod) Enable optimization
--source-map false (prod) Generate maps
--aot true AOT compilation
--watch false Rebuild on change
--stats-json false Bundle stats

Examples

Development build:

ng build --configuration development
ng build -c dev

Custom output:

ng build --output-path dist/my-app

With source maps:

ng build --source-map

Watch mode:

ng build --watch

Bundle analysis:

ng build --stats-json

Testing

ng test

Run tests:

ng test

Alias: ng t

Test Options

With coverage:

ng test --coverage

Single run:

ng test --watch=false

Vitest UI:

ng test --ui

Headless browser:

ng test --browsers=ChromeHeadless

Update & Add

ng update

Check for updates:

ng update

Update Angular:

ng update @angular/core @angular/cli

Update to next/beta:

ng update @angular/core --next

ng add

Add Angular Material:

ng add @angular/material

Add PWA:

ng add @angular/pwa

Add Firebase:

ng add @angular/fire

Add ESLint:

ng add @angular-eslint/schematics

Popular Packages

ng add @angular/material
ng add @angular/pwa
ng add @angular/fire
ng add @angular/localize
ng add @angular-eslint/schematics
ng add @ngrx/store
ng add @ng-bootstrap/ng-bootstrap

Linting & Deploy

ng lint

Add linter first:

ng add @angular-eslint/schematics

Run linter:

ng lint

Fix automatically:

ng lint --fix

ng deploy

Deploy (requires builder):

ng deploy

Examples:

ng add @angular/fire
ng deploy

Workspace Commands

Configuration

View config:

ng config

Set package manager:

ng config cli.packageManager yarn
ng config cli.packageManager pnpm

Analytics

Toggle analytics:

ng analytics on
ng analytics off

Cache

Clear cache:

ng cache clean

Cache info:

ng cache info

Other Commands

Open docs:

ng doc HttpClient
ng doc RouterModule

Shell completion:

ng completion

Run custom builder:

ng run project:target:config

Show versions:

ng version

Proxy Configuration

proxy.conf.json

Create proxy.conf.json:

{
  "/api/**": {
    "target": "http://localhost:3000",
    "secure": false,
    "changeOrigin": true
  }
}

Using Proxy

Start with proxy:

ng serve --proxy-config proxy.conf.json

Advanced Example

{
  "/api/**": {
    "target": "http://localhost:3000",
    "secure": false,
    "changeOrigin": true,
    "pathRewrite": {
      "^/api": ""
    },
    "logLevel": "debug"
  }
}

angular.json

Structure

Basic structure:

{
  "projects": {
    "my-app": {
      "architect": {
        "build": {
          "builder": "@angular/build:application",
          "options": {
            "outputPath": "dist/my-app",
            "index": "src/index.html",
            "browser": "src/main.ts",
            "styles": ["src/styles.css"],
            "scripts": []
          },
          "configurations": {
            "production": {
              "optimization": true,
              "sourceMap": false
            },
            "development": {
              "optimization": false
            }
          }
        }
      }
    }
  }
}

Custom Configuration

Add custom config:

{
  "configurations": {
    "staging": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.staging.ts"
        }
      ]
    }
  }
}

Use it:

ng build --configuration staging
ng serve -c staging

Shortcuts

Command Aliases

Full Alias Command
ng generate ng g Generate schematic
ng serve ng s Start dev server
ng serve ng dev Start dev server
ng build ng b Build project
ng test ng t Run tests
ng component ng c Generate component
ng service ng s Generate service
ng module ng m Generate module
ng directive ng d Generate directive
ng pipe ng p Generate pipe
ng guard ng g Generate guard

Option Aliases

Full Alias
--inline-template -t
--inline-style -s
--skip-tests -S
--configuration -c
--prefix -p
--open -o

Gotchas

Default Changes

⚠️ --standalone=true is default (Angular 19+)

⚠️ Vitest is default test runner (Angular 18+)

⚠️ No default linter — must ng add @angular-eslint/schematics

⚠️ Guards are functional by default (not class-based)

⚠️ --prod deprecated → use --configuration production

Common Issues

⚠️ Proxy config changes require ng serve restart

⚠️ Build budgets in angular.json can fail builds

⚠️ ng generate defaults configurable in angular.json schematics

⚠️ Port 4200 must be available for ng serve

⚠️ Global CLI and local CLI versions should match

Also see