Tutorials

Angular CLI Install | Getting Started

The Angular CLI is the key to rapidly building Angular applications without manual configuration. In this guide, we'll walk you through installing the CLI, creating a new project, and running it locally. Experience the speed and simplicity of project setup with a few straightforward commands.

Key Takeaways

  • The Angular CLI simplifies Angular project setup, reducing manual configuration.
  • Installation requires Node.js and npm, handled via simple CLI commands.
  • Create new apps effortlessly with ng new <app-name> and manage them with ng serve.

Installing the Angular CLI

Ensure you have Node.js (version 16.x or greater) installed, then use npm to install the Angular CLI:

npm install -g @angular/cli

Verify the installation with:

ng version

You should see the Angular CLI version in your console if everything is installed correctly.

Creating a new Angular app

To create a new Angular app, navigate to your desired directory and run:

ng new my-angular-app

This command sets up a new Angular project with all necessary configurations and dependencies, ready to go out of the box.

Running the app

After creating your app, navigate into the project directory:

cd my-angular-app

Start the development server with:

ng serve

Visit localhost:4200 in your browser to see your new Angular app running. The server includes live-reload support, refreshing automatically with any code changes.

CLI Features and Configuration

Project Setup

Running ng new configures essential files like package.json, tsconfig.app.json, and bootstraps your app with main.ts.

Component and Module Setup

The generated app.module.ts and components like app.component.ts come ready with TypeScript, HTML, and CSS templates for a complete setup.

Testing

Your project supports unit tests with karma and end-to-end tests with protractor, including generated spec files for component testing.

That was easy!

In just a matter of minutes, you've set up a complete Angular environment using the CLI. The automated processes save significant time compared to manual setup.

FAQ

What version of Node.js is required to use Angular CLI?

Node.js version 16.x or greater is recommended to ensure compatibility with the latest Angular CLI features.

How do I update the Angular CLI?

To update the Angular CLI, run: npm update -g @angular/cli. This command updates the global installation to the latest version.

Mastering the tech interviewWhat everyone is doing wrong in tech interviews