Angular CLI – A command line interface for Angular

Angular CLI (Command Line Interface) is a high quality development tool-set for developers. Angular CLI features can highly improve the quality of your code and save you a lot of time. The big part of getting started with Angular is the set up. With the help of Angular CLI you can easily set up the project and also it allows you to do the following things.

  • Create a new angular application
  • Run a development server
  • Add features to your existing angular application
  • Run your application’s unit tests
  • Run your application’s end-to-end (E2E) tests
  • Build your application for deployment to production

Before you can use the Angular CLI, you must have node.js 6.9.0 or above installed on your system, if you already have node.js installed, you can verify the versions by running

$ node -v  // Dsiplay the node.js version

Related: What you need to know about Angular CLI to improve your code

Installing Angular CLI

To install CLI, run

$ npm install -g @angular/cli

That’s it! Now you can start using the CLI to build your applications.

Creating a New Angular Application

To create new app, just run

$ ng new my-app

At this point you have a working Angular application and your new directory my-app looks like

Running Your Application

To preview your new application in your browser, navigate to its directory

$ cd my-app

and run

$ ng serve

You can now open your browser and navigate to http://localhost:4200/ to see your application in action

Generate Parts of Your Application

Using ng generate command you can create a new component, Directive, Services, Module, Class, Pipe, Route and so on.

You can use the ng generate (or just ng g) command to add features to your existing application:

Add a class to your application
ng generate class

Add a component to your application
ng generate component

Add a directive to your application
ng generate directive

Add an enum to your application
ng generate enum

Add a module to your application
ng generate module

Add a pipe to your application
ng generate pipe

Add a service to your application
ng generate service

Angular-cli will add reference to components, directives and pipes automatically in the app.module.ts.

Building Your Application for Production

Running ng serve builds and bundles your Angular application automatically to a virtual file system during development. However, when your application is ready for production, you will need real files that you can deploy to your server.

To build and bundle your application for deployment, run:$ ng build

Reference links:


  • Pradeep. B.P. works as Software Engineer with Trigent Software. He has over 4 years of experience in the field of Web Applications development. His areas of technical expertise include HTML5, CSS3, JavaScript, jQuery, Bootstrap, WordPress, Angular JS 2.0. Pradeep likes to learn something new everyday.