“The only way to learn a new programming language is by writing programs in it.”
― Dennis Ritchie
Table of Content
- Requirements and Installation Process
To make things easier and product development faster, a library like jQuery was introduced in 2006.
Later on, in 2010 Angular js was created by Google. It became the first framework that provided a complete architecture for front-end application development.
Fast forward to today, and we have the big 3 that dominate the world of frontend web development (Angular, React, and Vue)
Each of these tools is unique and can perform the same function effectively. One fact that cannot be ignored is that there will always be a debate about which is better among the three, but in this article, our focus is on how to set them up on our machine.
Initially released by Google on 14th September 2016. It is completely different from Angular Js which was created years earlier by the Google team. Angular was created to serve as an alternative to Angular Js which has been placed on long term support until December 31, 2021.
At first release, Angular was initially called “Angular 2“. However, this caused a lot of confusion, and the name Angular without any suffix was chosen.
As of today, the latest release is version 10 which was released June 24, 2020.
Initially released on May 29, 2013, it is maintained by Facebook and a community of developers.
Created by Evan You, it was released in February of 2014. The creator Evan You worked on Angular Js originally at Google.
Requirements and Installation Process
We are going to install and run the Angular application in 4 easy steps:
Step 1: Download Node.js
The installation of Node comes along with NPM(Node Package Manager). NPM is the tool we will be using in the terminal to install other 3rd party libraries needed to run an Angular application.
If you don’t have Node.js installed on your machine, you can do that here
Step 2: Install The Angular CLI
Once Node.js has been installed on your machine, this stage involves installing the Angular CLI. We can do this by opening the terminal and running the command below:
npm install -g @angular/cli
Once the installation process is complete, you can type ng v in the terminal to confirm if it was successfully installed. That command will display the version of Angular you have running on your machine.
Step 3: Create a New Angular Project
Now that the Angular CLI has been installed, we now have access to the ng command in our terminal.
To create a new project we can run the command below:
ng new my-first-project
ng represents the angular command, new represents the fact it’s a new project and my-first-project signifies the name of our project.
Once the installation process is complete and the needed dependencies and files are downloaded, the next thing to do is to navigate into the project directory. We can do this by running the cd my-first-project command in the terminal.
Step 4: Run The Application
To run the application and display it on the browser, we will run another command from the terminal, shown below:
ng serve --open
Once this command has executed successfully, a tab should open in the browser showing the Angular boilerplate template
We just successfully run an Angular application. By default, our application will be running on localhost:4200
To prepare and bundle our app for production, we can run the ng build –prod command in the terminal. This will minimize and bundle our application making it ready for deployment.
We will work on two different ways of setting up a React project. The first one will be done using the create-react-app command, and the second one will be set up using Webpack and Babel.
Using The Create-react-app Command
This will be done in two(2) easy steps.
Step 1: Install Create-react-app
To have access to the create-react-app command, we need to install it on the terminal using npm. The command to that is shown below:
npm i create-react-app
Step 2: Create Project With NPX
We can now create a new project using npx. npx is a package runner tool that comes with npm version 5.2 and above. It allows us to create a new React project from the terminal by running the command below:
npx create-react-app my-first-app
cd my-first-app npm start
Above we created a new project called
my-first-app , we moved into the newly created project directory and started the project with npm.
By default, our project will be running on localhost:3000 in the browser. To prepare and bundle our app for production, we can run the npm run build command in the terminal.
Using Webpack and Babel
This involves a much longer process to run React. It will be done in 7 steps.
Step 1: Create The Project Folder
To install React using this method, we will create a new folder to install all the required dependencies. We can do this with the command below:
C:Usersuser> mkdir my-first-react-app C:Usersuser>
Step 2: Package.JSON
To install any dependencies, a package.json file is required to be installed in the project. To do this, we will run the npm init command in our project directory, from the terminal.
C:Usersusermy-first-react-app> npm init
The above command will require some information like the name, author, description version, etc. to be filled in the terminal. A sample of this can be found below:
You can skip filling all the data above by adding a -y flag to the npm init command.
npm init -y
Step 3: Install React and React Dom
So for React to work on our project, we need to install React and React Dom. To do this, we will run the command below:
C:Usersusermy-first-react-app> npm install react
C:Usersusermy-first-react-app> npm install react-dom
Step 4: Install Webpack and Babel
Let’s start with Webpack. Webpack is going to require three things to be installed.
The Webpack CLI, the Webpack Dev Server, and Webpack itself. All this can be done with the command below:
C:Usersusermy-first-react-app>npm install webpack
webpack-dev-server webpack-cli --save
Next up to install is Babel. Some of the Babel dependencies we are going to install include:
- Babel-core – Gives us access to the Node API.
Now let us install them by running the command below:
Babel is now installed!
Step 5: Create All Necessary Files
We need to create the files needed for us to set up and bootstrap the application. These files are going to be created in the root folder (my-first-react-app) of the application. They include:
Step 6: Configure Rules, Loaders, and Dev Servers
The next step is to open up the files and complete the setup. We start with the index.html file.
The important thing to take note of in our index.html file is the div with the id called app.
This is the part of our code that will be shown in the browser. When we eventually run the application, we should see a Hello world text.
The App.js is imported into the index.js file, this enables us to render it into the browser.
From the above code, we set the entry point of the application as index.js. Then the output path is where we will bundle the app for production. This will be done inside the dist folder.
In the mode object, we can either set the app to be bundled for either production or development mode. This will be done in the package.json file
Step 7: Setup Package.JSON File
On opening the package.json file, you may come across “test” “echo “Error: no test specified” && exit 1″ inside the scripts object. You should clear it off and post the above code in the scripts object.
In the build-for-windows object, we set up our app to run in development mode. We can change it to production when we are ready to deploy the app.
Now inside the root of our application, we can start our application with the command below, like so:
The app will run on http://localhost:8080 by default. If we go to this address on the browser, we should see Hello World on display.
To generate the bundle needed for deployment, we can run the command below in the terminal.
C:Usersusermy-first-react-app>npm run build-for-windows
We will be setting up Vue with the Vue CLI. This will be done using yarn in 3 easy steps.
Note: In case you don’t have yarn installed on your machine, you can install it with npm by running the npm i yarn command.
Step 1: Install The Vue CLI
We do this by running the command below:
yarn install -g vue-cli
With this, we have installed Vue globally on our machine.
Step 2: Create a New Vue Project
To complete this step we run the command below:
vue create first-vue-app
This will show the options below in the terminal.
Vue CLI v4.5.6 Please pick a preset:
(Use arrow keys)
> default (babel, eslint)
Manually select features
To keep things at a basic level, we can select the default option.
Step 3: Run Vue App
To run the application, we need to move into the project directory which is first-Vue-app with the command below:
cd first-vue-app yarn serve
Now, the project will become accessible at http://localhost:8080/ by default in your browser!
So that is pretty much everything that is needed to set up an Angular, React, or Vue application. If you have any issue during the installation process, please feel free to drop a comment, I will be sure to respond to it.