This is the second article of this series, in previous articles we had a brief introduction to React and covered the required concepts of React like JSX, Virtual DOM and one way data binding. If you didn'tt read the previous article then I recommended you first read it.
Today we will learn how to set up a development environment for React. I discuss three different methods to setup a React project. These three methods are
- Using the NPM
- Using Visual Studio 2017 SPA templates
- Using the Webpack and Babel
Let’s read about each method one by one. Before starting any method there will be npm installed in your system, without npm we can’t setup the React environment. So if npm is not installed in your system then first of all go to the Node.js official website and download and install the node.js . When you install the Node.js npm will be automatically installed in your system.
Using the NPM
Download React Global Packages
Now open your command line terminal and paste the following line of code and press enter.
“npm install -g create-react-app”
Above command install the global packages for React.

Create React App
After installing the React global packages now run “create-react-app reactapp” command, this command will create a React project and name this project as “reactapp”.

Run the Project:
After creating the project now change the directory and run “cd reactapp” command. Now you are in root directory of the project again run the “npm start” command this command run the React project on “3000” port.

In my case port number 3000 is used by another application so it runs the project on 3001 port. When you open the “localhost:3000” URL in your browser you will get following output.

If you are getting the above screen, then congratulations you successfully configure and run the React application. Don’t worry about the code written into the project code we will cover all the topics in the next article.
Using Visual Studio SPA Templates
If you are using Visual Studio 2017 then the easiest way to get started is by using one of the project templates which are made available. These plug into the standard dotnet new command and work on Windows and Mac in addition to Linux. To install the (Single Page Application)SPA templates, open the command prompt and run the command given below.
dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

The command given above takes some time and installs several templates for SPA like Angular, Knockout.js, React etc. The benefit of all these templates are that we don’t need to worry about the whole setup process.
To generate a new project, create an empty folder and name this project as reactCore here. After creating an empty folder, now change the directory and go to this project. Now, run the command “dotnet new React“

This command creates a template project for React Application. Now, run “dotnet restore” commanpm nd. This command builds MSBuild file and restore all .NET dependencies.

After installing all the .NET dependencies, now we install Node.js dependencies. Run “npm install” command. This command takes a couple of minutes to install the required Node.js dependencies.

After creating the template project and installing all the required dependencies, now run “start reactCore.csproj” command. This command will open your project in Visual Studio.


Now, press Ctrl + F5 and run the project. When you run this project you will get the following screens.


Using Webpack and Babel
So far we set up the React Environment set up using the npm and Visual Studio 2017 SPA templates. Now we will focus on the Webpack and babel to setup the React project. I like this method and recommend this method among all three methods because it provides a full functionality to install the required packages and makes the configuration manually. If you see the project structure of the project created in Visual Studio 2017 then you will find that webpack and babel is also used there. So now we create the same project with manual configuration. Let’s start the setup.
First of all create an empty folder and name this folder as “reactwebpack”, after creating the folder now open this folder into any IDE; here I am using the Visual Studio Code. If you are new to Webpack then read this article. From this article you will get a brief intro about the webpack and learn what webpack is and how it works.
Step 1 Create Package.json file
Now open the command line terminal and run the “npm init” command. When you run this command it will ask several question, you don’t need to answer all the questions just press enter and skip the questions.
After completing this process you will find that a “package.json” file has been created in your project. Package.json is main configuration file of our project and contains the information of the packages uses in our project.

Step 2 Install the Required Libraries
Now we needs to install the required libraries to run and configure the application. Let’s install all these libraries.











Goran TesicPosted Feb 24, 2018, 7:12 AM
Hello Pankaj! First of all thank you very much for excellent articles about react. Regarding this article I have a question. I use third method and the application is running as expected, but bundle.js file is not created. Could you, please, explain why is not created and how to fix it? Thank you in advance.
Vijay BhaskarPosted Aug 5, 2017, 2:30 PM
Pankaj, I have created app using the first method (npm). I didn't find *.jsx file in generated code. Please can you help. I have seen that app.js having jsx code, but it is app.js file.
lok nadhPosted Jul 28, 2017, 3:42 AM
Getting below error. Help me on this. I am using windows 64-bit.Windows_NT 6.1.7601argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "ins bel-core" "babel-loader" "babel-preset-react" "babel-preset-es2015" "babel-preset-stage-2" "--save-dev" node v6.11.1 npm v3.10.10 path C:\lok\reactwebpack\node_modules\babel-register code EPERM errno -4048 syscall rename
lok nadhPosted Jul 27, 2017, 8:43 AM
Great & Thanks for very clear explanation...I am facing issue. could you help on this
Upendra Pratap ShahiPosted Jun 23, 2017, 7:19 AM
Great one stuff Pankaj Kumar Choudhary..