? Topic: Angular CLI
The Angular CLI (Command Line Interface) is a powerful tool that helps developers quickly create, build, test, and deploy Angular applications. It automates repetitive tasks and provides a structured, opinionated way of managing Angular projects so you can focus more on writing features and less on manual setup.
ng serve.ng build.Angular CLI commands follow a consistent structure:
ng <command> [options]
ng new my-app – creates a new Angular project called my-app.ng serve – runs a local dev server at http://localhost:4200 by default.ng generate component my-component – generates a new component with all required files.ng build – builds the project into the dist/ folder.ng test – runs unit tests using the configured test runner.ng e2e – runs end-to-end tests (if configured in your project).After installing Node.js and npm, install the Angular CLI globally:
# Install Angular CLI globally using npm
npm install -g @angular/cli
Create a fresh Angular project called my-app:
# Create a new Angular project named "my-app"
ng new my-app
Navigate into the project folder and start the dev server:
# Move into project folder and start dev server
cd my-app
ng serve
Use generators to quickly create building blocks for your app:
// Generate a component and a service using Angular CLI
ng generate component my-component
ng generate service my-service
When your app is ready, build and test it using these commands:
// Build the project for production
ng build
// Run unit tests
ng test
// Run end-to-end tests (if configured)
ng e2e
ng new my-appmy-app with a complete Angular project structure, installs dependencies, and sets up configuration files like angular.json, package.json, and initial components.ng servehttp://localhost:4200), and automatically reloads the browser when you change your code.ng generate component my-componentng builddist/ folder that you can deploy to a server.ng help or ng <command> --help to explore all available options.ng g c my-component instead of ng generate component my-component.npm install before ng serve to install dependencies.cli-demo using ng new cli-demo.cli-demo, generate a component named hello-world and display a welcome message in its template.ng serve and open the app in your browser.ng build and explore the generated files in the dist/ folder.ng g s log-service to generate a service and inject it into a component.