Angular CLI is a command-line interface (CLI) to automate your development workflow. It allows you to:
Before you can use Angular CLI, you must have Node.js 6.9.0 and npm 3.0.0 or higher installed on your system.
If you already have Node.js and npm installed, you can verify their version by running:
$ node -v # => displays your Node.js version
$ npm -v # => displays your npm version
Once you have Node.js installed, you can use the npm command to install TypeScript:
$ npm install -g typescript
Although TypeScript is technically not an absolute requirement, it’s highly recommended by the Angular team, so I recommend you install it to make working with Angular as comfortable as possible.
$ npm install -g @angular/cli
This will install the ng command globally on your system.
To verify whether your installation completed successfully, you can run this:
$ ng version
Angular CLI: 11.2.5
Node: 12.16.1
OS: darwin x64
There are two ways to create a new application using Angular CLI:
So ng new is similar to ng init, except that it also creates a directory for you.
Assuming you haven’t created a directory yet, let’s use ng new to create a new project:
ng new my-app
Run $ ng generate --help to see all available options of your locally installed Angular CLI.
To preview your new application in your browser, navigate to its directory:
$ cd my-app
$ ng serve
to start the built-in development server on port 4200
You can use the ng generate command to add features to your existing application:
Angular CLI automatically configures the Karma test runner for you when your application is initially created.
Running all unit tests of your application thus implies running all unit tests specified in all files ending in .spec.ts in all directories inside your src directory.
$ ng test
Angular CLI automatically configures Protractor for you when your application is initially created.
$ ng e2e
To build and bundle your application for deployment, run:
$ ng build