Environment Setup in Angular
his chapter explains how to set up the Angular development environment, including installation of Node.js and Angular CLI, creating your first Angular project, understanding the folder structure, and running the Angular development server.
1. Install Node.js and Angular CLI
Before creating an Angular application, you must install Node.js and the Angular CLI.
Install Node.js
- Download Node.js from the official website.
- After installation, verify using:
Install Angular CLI
The Angular CLI (Command Line Interface) is required to create and manage Angular projects.
This installs Angular CLI globally on your system.
2. Create Your First Angular App
Once the CLI is installed, you can create your first application.
Create a new project
During project creation, Angular CLI will ask:
- Whether to add routing
- Which stylesheet format to use (CSS, SCSS, etc.)
After completion, a full Angular project structure is created.
3. Project Folder Structure
A basic Angular project contains the following main folders and files:
node_modules
Contains all installed dependencies.
src
This is the main application folder.
Inside src:
- app/ : Contains the root module and main components.
- assets/ : Contains images, JSON files, and static resources.
- environments/ : Development and production environment files.
- index.html : Main HTML file.
- main.ts : Starting point of the Angular application.
- styles.css : Global styles.
angular.json
Main configuration file for Angular build and project settings.
package.json
Lists all installed dependencies and npm scripts.
4. Angular Development Server
After creating the project, open the folder and run:
The development server starts and compiles your application.
Access the application
Open your browser and go to:
This displays the default Angular welcome page.
Development Server Features
- Auto reload on file changes
- Real-time compilation
- Helpful error messages in the console