What is React?
So, let’s proceed with the installation of React in Windows.
How to Install React Js in Windows
So before installing react, we’ll require to install Node js and npm. Node js and npm are the dependencies manager that requires to develop any React js application. For downloading, just go to the official website of Node.js and download the latest version from there.
So, currently, the latest version is 13.12.0. But, we will install the stable version that is 12.16.1 LTS. So, I recommend you to install the stable version. After downloading, let’s install it.
Install Node.js in Windows
The installation of the Node.js installer is the same as the other in Windows. Simply double click on the installer and proceed with the installation process. After completing the installation of Node.js we will install React js. So, let’s finish the installation.
After clicking on Run, a setup wizard will open. So, just follow the recommended options and click to next.
Accept the license agreement and move to the next step.
We will require installing Node.js to global so that we can access it globally.
Here the installation process is started. It will take a few seconds to complete the installation.
So, here the installation has finished.
You can check whether node.js has installed successfully or not. Just open the command prompt and simply enter the below command.
The Node.js contains the npm so with the current installation of Node.js, npm has been installed too. Similarly, you can check the npm version like the node.
Now, the Windows system is ready to install react js. Let’s create our first React js application.
Install React js in Windows
Open the terminal or command prompt or Windows PowerShell and just enter the below command.
npx create-react-app my-app
Here, my-app is the application name that will be going to create.
It will take a few minutes to install the required libraries with the react js application. So, just hold on while it completes the app setup.
my-app is the name of the application. The command npx create-react-app my-app creates a folder called my-app which is the project folder. To test if everything has been installed properly, go into the project folder and start the following command.
cd my-app npm start
Now, go to your browser and open the URL localhost:3000
You should be able to see that your application is running. The application will look like this in your browser:
Basic folder structure
When you have created the project, you have noticed that it creates a bunch of files. Like this
Here, I will explain some of the important files and folders that you should be knowledgeable about.
- package.json: This file contains a list of all node dependencies which are needed.
- public/index.html: When the application starts this is the first page that has loaded. This is the only HTML file in the entire project since React is generally written using JSX. This file has a line of code <div id=”root”></div> . This line is very important because all the application components are loaded into this div.
- src/index.js: This is a js file corresponding to index.html. This file contains the code ReactDOM.render(<App />, document.getElementById(‘root’)); . This means the App component has to be loaded into an html element with id root. This means the div element is present in index.html.
- src/index.css: This is the CSS file corresponding to the App component.
npm run build
After running the command npm run build you will see that build folder is created in your project.
So, in the very initial post of React, we learned how to install React in Windows as well as Ubuntu. Also, I have given you a short explanation of React and npm. That will help you out to understand the core structure of the React. I hope, you will be happy to learn here. In the upcoming post, I will try to post the real type of demo which can be implemented in your real projects. In the next post, we will grab the CRUD Application in React using the RESTful APIs. That will help you to learn the APIs implementation with the React application.