React Installation Process

Introduction
 
In this article, I am going to talk about the React installation process for a beginner who doesn't know what the prerequisites are to install React, and what the different ways to install React are.
 
You may take an overview of React from my first React article where I have described the fundamental overview of React Programming.
 
Prerequisites
 
First, you need to install Node if your machine doesn't have Node installed from earlier. According to the React organization, the version of node must be >= v6
 
Note 
For this article, I am using Visual Studio Code which is one of the best editors for JavaScript programming, but it's optional. You may use any one editor according to your choice like:
 
Atom, Sublime Text, WebStorm etc.
 
Step 1 - Install Node
 
As I mentioned above the version of Node should be >= v6. First, download the appropriate version from https://nodejs.org. Here, I am going to install the latest version of Node from NodeJs portal.
 
My machine has a Windows Operating System so I am going to download Node for Windows. 
 
 
 
After completion of the download, right click on the installer file node-v8.9.3-x64 and select Install option from the context menu and follow up the further steps suggested by the wizard.
 
If you want to know more about Node installation, click here 
 
Note 
If you are not using Windows OS, you may download the appropriate node from the following link.
Check Node Version
If you have already installed, you may check the version of Node by execution the following command at your command prompt terminal.
  1. C:\Windows\system32>node --version  :: # or node -v to check the version of node
  2. v8.9.3  
  3.   
  4. C:\Windows\system32>  
 If installed version is < 6 then you need to update your node
 
Now, I am going to create a new root directory "ReactProgramming" in drive D where I will create a sample application to explain about the installation process. You may create or select a directory according to your choice.
  1. D:\>mkdir ReactSampleApp  
  2. D:\>cd ReactSampleApp  
  3. D:\ReactProgramming>  
Step 2
 
React Installation Command.
  1. D:\ReactProgramming>npm install -g create-react-app  :: or D:\ReactSampleApp>npm i -g create-react-app
Above  command is used to install react globally.
  • -g stands for global 
  • create-react-app is a react package which includes the global command to create react app.
Now, execute the following command to create a react application.

create-react-app <app name> 
  1. D:\ReactSampleApp>D:\ReactSampleApp>create-react-app SampleApp  
ErrorAtAppName
  1. D:\ReactSampleApp>D:\ReactSampleApp>create-react-app sample-app    
Once you execute this command it will take few minutes to load the dependent packages for React. You will see the following screen after successful execution of the above command.
 
AppCreated 
 
Now an application with the name "sample-app" has been created successfully with all default packages. If we see inside the sample-app directory, it contains the following files and directory.
 
D:\ReactSampleApp\sample-app 
  • node_modules <directory> - It contains react packages like react-dom, react-body etc.
  • public <directory> - It contains a index.html, favicon icon and manifest.json files.
  • src <directory> - It contains application's static files like css, js , logo and App.js  files
  • package.json
  • package-lock-json
  • README.md
  • .gitignore
Step 3
 
Now execute the command npm <space> start to run application.
  1. D:\ReactSampleApp\sample-app>npm start  
It takes few seconds to start the development server. Once the server is started you may see the follwing message on the command prompt.
 
Compiled Successfully
 
You can now view sample-app in the broser.
http://localhost:3000/
 
Now this sample aplication is running. 
 
appstarted 
 
Using React With Existing Web Application
 
We can add React packages with existing web applications by executing the following commands on comand prompt.
  1. D:/MyWebsite>npm install --save react react-dom  
Or

We can use CDN for React as well to enable React in our existing web applications. 
  1. <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>  
  2. <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>  
You may read more about react CND from here.