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 my-new-class
Add a component to your application
ng generate component my-new-component
Add a directive to your application
ng generate directive my-new-directive
Add an enum to your application
ng generate enum my-new-enum
Add a module to your application
ng generate module my-new-module
Add a pipe to your application
ng generate pipemy-new-pipe
Add a service to your application
ng generate service my-new-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:
https://angular.io/docs/ts/latest/cli-quickstart.html
https://github.com/angular/angular-cli