Commands of the Angular CLI
Discover how to use essential Angular CLI commands to streamline your development workflow. This lesson helps you understand commands for creating projects, generating components, running tests, and managing builds, enabling smoother Angular app development.
We'll cover the following...
What is a command?
So we know the Angular CLI can be used to start a new application and also run the new application in the browser, but that’s not all it can do. There are other commands which can be used as we are developing our applications.
A command is a term for instructions we type into the Command Line Interface (CLI).
Angular commands
Let’s see a list of available commands:
| Angular Command | Purpose |
|---|---|
| ng add | Used to add third-party libraries to an existing application, we will be using this soon to add Angular Material |
| ng build | Used to compile the complete application into a /dist folder or a folder provided by an argument |
| ng config | Allows you to either view or set configuration settings for your app; these configuration settings can be passed as JSON |
| ng doc | Opens the official Angular docs website; if you want to find a specific topic, add the keyword as an argument |
| ng e2e | This will run the end-to-end tests of the application |
| ng generate | Command to create/generate new components, services, and other parts of your Angular application. We will use this command a lot over the next few chapters |
| ng help | Provides a help menu for the Angular CLI |
| ng lint | Runs linting over your application’s codebase |
| ng new | Starts the process to create a new Angular application application |
| ng run | Starts running a custom target for your application. In your package.json file, you can add custom commands that ng run will start for you |
| ng serve | Starts the local Node server so you can access the site in the browser |
| ng test | Starts the running of all the Unit Tests you create for your application |
| ng update | Updates the application and any dependencies in the application, very useful when a new version of Angular is released |
| ng version | Tells you the version number of the Angular CLI currently being used |
| ng xi18n | Extracts any xi18n messages within your application, used as part of adding multi-language support to your application |
That is a lot of commands, and there may be more coming in future releases of the Angular CLI. This shows how much you can do with the CLI and how you will rely on it as part of your day-to-day Angular development.
Practice time
You can execute the above-mentioned commands within the terminal window.
To do this, we need to open up the terminal and navigate to the newly created angular folder using the following command:
cd usr/local/educative/angular
Then we can execute any of the above commands in the angular project.
📝 Note: Click the terminal window and see what happens!
Clicking the terminal window will show you the version of Angular installed on your machine. You can play around with the terminal by executing the given Angular commands.