Angular is a popular front-end web application framework created by Google. It allows developers to easily create robust, dynamic single-page applications (SPAs). To install Angular on Windows, you must first install Node.js, npm (Node Package Manager), TypeScript, and the Angular CLI (Command Line Interface).
This blog will walk you through the process of configuring your development environment and provide you with the necessary Angular CLI commands to get your project started.
To know more about full stack development, check out the best Full Stack course.
What is Node.js?
The very first thing required to install is Node.js. (If already installed, skip this part and jump to the next part of this blog.)
Node.js is an open-source and cross-platform JavaScript run-time environment that allows to execute JavaScript code outside of a browser (on the Server-side). Node.js is responsible to manage and install all npm dependencies for your Angular application. It provides the required libraries to run the Angular project. Node.js acts as a run-time environment for any Angular application which uses servers over localhost. For more information on Node.js refer to official docs.
Angular requires the latest/stable version of Node.js in order to continue. Go to the official website in order to install Node.js on your machine locally.
You can install any version, the current one or latest stable version, as per your need. Just click on the button and it will start downloading the package on your machine.
Once downloaded click on the icons downloaded and follow the steps, till the installation is completed. To check the version installed of Node.js you can use the following command in a terminal/console window. —
node -v
or
node — — version
Prerequisites to Install Angular in Windows
Before embarking on the journey to install angular in windows, it's imperative to ensure that your system meets the necessary prerequisites for Angular development.
A. Hardware Requirements
Angular, being a sophisticated framework, doesn't demand extravagant hardware. A standard Windows PC or laptop with a reasonably fast processor and at least 8GB of RAM is generally suitable for Angular development. However, for larger projects, consider upgrading to 16GB or more.
B. Software Requirements
The backbone of Angular development is Node.js. Make sure to have the latest version of Node.js installed on your Windows machine. Angular relies on Node.js for package management, server-side functionality, and running scripts.
C. Additional libraries or tools to be installed in prior (if any)
Depending on the specific requirements of your project, you might need additional tools or libraries. Some projects may require specific versions of Node.js or additional packages. Ensure that you review your project documentation for any such prerequisites.
This will ensure that we have a system that will be able to install angular on windows.
How to Install Angular in Windows? Step-by-Step
Now, let's delve into the comprehensive step-by-step process to install Angular in windows machine:
Step 1: Installing Node.js
Begin by visiting the official Node.js website (https://nodejs.org/) and downloading the installer. Follow the on-screen instructions to complete the installation. Once installed, open a command prompt and verify Node.js and npm (Node Package Manager) installation by running the following commands:
node -v
npm -v
This ensures that Node.js is installed and accessible from the command line.
Step 2: Install TypeScript Globally (Optional)
1. Install Node.js and npm
- Download and install the most recent stable version of Node.js from the official website.
- The installation includes npm, which you'll use to install additional packages.
2. Install TypeScript Globally
- Launch Command Prompt or PowerShell as an administrator in your Windows machine.
- Use the following command for installing TypeScript globally:
npm install -g typescript
tsc -v
Step 3: Installing Angular CLI
With Node.js successfully installed, you can proceed to install Angular CLI (Command Line Interface) using npm. Open a command prompt and run the following command:
To install the Angular CLI on your machine, open the terminal window and run the following command:
npm install -g @angular/cli
where -g denotes that CLI is being installed globally to your machine, which means you can create or run any command of CLI anywhere on your machine. Once you run the above command CLI will be installed on your machine, and you can verify the version installed using the following command:
ng version
To know more about Angular CLI commands, you can refer to this blog which contains a number of commands to use.
Step 4: Creating a Project using Angular CLI
Now, let’s create our first ever Angular project using Angular CLI. Open your terminal window and type the command below on your machine.
ng new hello-world
Here ng is our CLI prefix, new denotes that we are creating a new project and hello-world is our project name. You can choose any name you want.
After running this command you will find the full architecture of the project in the directory where you run this command. The project folder will be something like below in the image -
Step 5: Angular Project Architecture
The first file to render on running this application will be index.html which present in the src folder.
- src folder contains Source files for the root-level application project.
- assets folder contains all the static assets like images, fonts, etc.
- node_modules This folder is created while you run npm installby package manager (npm) and it contains all the project dependencies or any third party modules required for the project.
- e2e folder contains all the source code related to Test Cases.You can customise it as per your requirements.
- README.md file is being used as documentation for the app.
- Package.json configures NPM dependencies which are available for the project in the workspace along with their versions specified.
One with the installation process of Angular application via CLI, it’s time to run the application locally. Angular CLI comes with complete tool-chain/commands for the development of front-end applications on your machine.
Run the following command on the terminal (Navigate to the project directory if you are not in that directory).
ng serve
or
ng serve --open
Angular CLI Commands
The Angular CLI is a powerful tool that makes development easier by providing commands for generating, creating, and running Angular applications.
1. Install Angular CLI:
After installing TypeScript, you should install the Angular CLI globally.
npm install -g @angular/cli
Verify your installation by using the following command, you will get the version that you will be using further:
ng version
2. Create a new Angular project:
Leverage the Angular CLI to create a new project:
ng new my-angular-app
Navigate into your newly created project directory:
ng serve
3. Open any browser and go to http://localhost:4200/ to see your application in running.
4. You can try some Angular CLI commands like:
To generate a new component, you can use the following command:
ng generate component dummy-component
To generate a new service:
ng generate service dummy-service
You could opt for our Angular training course that would help you build your knowledge on Angular framework right from basics to advanced topics with practical hands-on examples and guided training.
How to Test If Angular Installation in Windows is Properly Done?
The --open (or just -o) option automatically opens your browser to http://localhost:4200/.
ng servecommand will serve your application on localhost server which you can check by navigating to your browser with the below URL http://localhost:4200/. You can customise the port as per your requirement.
Accessing Angular Web Interface
ng serve command may take a few seconds to run your application, and once completed, you should see a web page similar to the following.
And we are done!Now you can make changes in the default component’s template which is app.component.html .
Also, moving forward, you can generate a number of components/service/routing files using CLI commands as per your requirements and keep learning.
Looking to enhance your programming skills? Dive into the world of Python with our unique python certification course. Unleash your coding potential and become a Python pro today!
How to Use Angular?
Now that Angular is installed, I will take you through understanding some basic concepts and usage of important blocks of angular that will help us understand the Angular ecosystem and build our knowledge on it.
A. Creating a Component
Components are the building blocks of an Angular application. Components are fundamental building blocks that encapsulate specific functionality and user interface elements within a web application.
A component in Angular is a TypeScript class that interacts with a corresponding HTML template and optional CSS styles. It follows a modular, reusable, and maintainable approach to structuring web applications.
Components in Angular follow a hierarchical structure, allowing for the composition of larger applications by combining smaller, self-contained components. This modular approach enhances code organization, reusability, and maintainability, facilitating collaborative development efforts.
Run the following command to generate a new component:
ng generate component my-component
This command creates the necessary files for an Angular component, including TypeScript, HTML, and CSS files.
B. Running Tests
Angular provides robust testing capabilities. Run the following command to execute tests:
ng test
This will run the tests defined in your project and provide feedback on their success or failure.
C. Exploring Angular Modules
Angular applications are modular. module is a logical container that groups related components, directives, pipes, and services, defining the boundaries and organization of an application. Modules help in organizing code, encapsulating functionality, and facilitating the reusability of components across different parts of an application.
Each Angular application has at least one module, the root module, which serves as the starting point for the application's execution. Additional modules can be created to organize and manage different features or sections within the application.
You can create a new module using the following command:
ng generate module my-module
Understanding how to organize and utilize modules is crucial for scalable and maintainable Angular applications.
D. Utilizing Angular Services
In Angular, services play a crucial role in promoting modularity, encapsulating business logic, and facilitating the sharing of data and functionality across different components. Services are singleton objects that are instantiated once and can be injected into various components or other services within an Angular application.
These injectable services in Angular often handle tasks such as fetching data from a server, managing application state, or encapsulating complex algorithms. By centralizing these functionalities within services, developers can achieve a more organized and scalable codebase.
You can generate a new service with the following command:
ng generate service my-service
Services play a crucial role in data sharing, and understanding their usage enhances the functionality of your Angular applications.
How to Uninstall Angular from Windows?
If, for any reason, you need to uninstall Angular, follow these steps:
Step 1: Uninstall Angular CLI
To remove Angular CLI from your system, open a command prompt and run the following command:
npm uninstall -g @angular/cli
This command uninstalls Angular CLI globally from your machine. The `-g` flag specifies the global scope.
Step 2: Remove Node.js
If you wish to remove Node.js as well, you can uninstall it using the standard Windows uninstallation process. Navigate to "Add or Remove Programs" in the Control Panel, locate Node.js, and uninstall it.
Removing Node.js will also uninstall npm, the Node Package Manager, as it comes bundled with Node.js.
It's always recommended to run the command
npm cache clean
After un installation of Angular CLI from your system in order to avoid unwanted errors while installing it again.
Conclusion
In conclusion, to install Angular on windows, you must first install Node.js, npm, TypeScript, and the Angular CLI. These tools establish a solid foundation for developing and managing Angular applications. By complying with this guide, you should be well prepared to begin your Angular development journey.
The powerful Angular CLI allows you to easily generate components, build applications, and serve them locally, making the development process simpler and enjoyable. Happy coding!
If you are looking out to build a career into Full Stack Development, then KnowledgeHut brings you the best Full Stack course that is Designed to get you hired, this power-packed Full-Stack Developer Bootcamp features best-in-class training, plenty of hands-on exercises and assignments with Cloud Labs, and so much more