Reading Time: 4 minutes
When we are done, you will have a React environment you can use to start development on your Liquid Web server.
The first step is to download the Node.js installer for Windows. Let’s use the latest Long Term Support (LTS) version for Windows and choose the 64-bit version, using the Windows Installer icon.
Once downloaded, we run the Node.js installer (.msi fuke) and follow the steps to complete the installation.
Now that we have Node.js installed, we can move on to the next step.
The Command Prompt Environment
We’ll need to use the command prompt (command line) to interact with Node.js and the Node Package Manager (NPM) to install React. Let’s take a few minutes to cover the commands we’ll need to use to get around. Here are the basic commands we will need to get around and create folders/directories:
Open a Command Prompt in Windows
Click the Start Menu (1), start typing the word command (2), then choose either Command Prompt or the Node.js command prompt (3) — either choice will work.
A command prompt window will open with the path showing as C:\Users\<username> where the <username> on your system will be the user you are logged in as.
To execute a command, we type the command and any required options, then press Enter to execute it and see the results. Let’s walk through each of the commands listed above to see what happens:
Let’s look at the contents of the downloads folder with this command:
The path shows we are still in the directory C:\Users\ReactUser>, however, we are looking at the contents of C:\Users\ReactUser\downloads and we see that it has one file. Let’s move to the downloads directory with this command:
We’ve changed to the downloads folder as the command prompt shows C:\Users\ReactUser\Downloads>. You can use the dir command to see the contents of this directory/folder. Next, let’s go back to the previous directory with this command:
Now we are back to where we started. Let’s create a new directory for our first project and name it reactproject1. We’ll use the command:
Again, we use the dir command to list the files within our current folder.
If you want to learn more about commands, please check out these links:
Install React on Windows
There are two ways to install React for your projects. Let’s look at each approach so that you can decide which one you prefer to use.
- Create a project folder
- Change to the project folder
- Create a package.json file
- Install React and other modules you choose
This install option allows you to full control over everything that is installed and defined as dependencies.
Step 1: To get started, we need to open a command prompt.
Step 2: Create a project folder named reactproject1:
Press Enter to execute the command, and we get a new directory called reactproject1. If you did this as part of the Command Prompt examples, you could skip this step as it will tell you that it already exists.
Step 3: Move to the project folder, using cd reactproject1, so we can install React into it.
At this point, you will see your prompt indicate C:\Users\ReactUser\reactproject1.
Step 4: Create a package.json file, the following command will walk you through creating a package.json file.
Step 5: Install React and other modules using npm install — save react, thiswill install React into your project and update the package.json file with dependencies.
npm install --save react
We can install additional packages using npm install — save and the name of the package we want to install. Here we are installing react-dom: npm install — save react-dom
npm install --save react-dom
- Install Create-React-App package to simplify the process of creating and installing React into your projects
Step 1: To get started, we need to open a command prompt and type npm install -g create-react-app. This installs the Create-React-App module which makes it very easy to create and deploy React into projects with a single command.
When using create-react-app ensure you are in the desired directory/folder location as this command will create the project folder in the current path.
npm install -g create-react-appCreate-React-App is installed in the following location: C:\Users\<username>\AppData\Roaming\npm\node_modules\create-react-app\
Once Create-React-App is installed, we can use it to create a project folder and install React and dependencies automatically.
To make sure you are in the desired directory when creating a new project, you can use dir to see where you are, and cd <directory_name> or cd.. to get to the desired location.
Step 2: To create a new project and deploy React into it, we run create-react-app <project_name>. Let’s do this to create reactproject2.
The entire process is automated and begins with creating a new React app folder for the project, then installs packages and dependencies. The default packages include react, react-dom, and react-scripts. The installation will take a few minutes.
Run a React Project Application
To run our new project, we need to use the command prompt to change to the project folder, then start it. The cd reactproject2 command will take us to the reactproject2 folder.
And npm start will run the project application.
The default browser will open and load the project:
To learn more about React, you may find these links helpful:
You now have your environment set for building out projects! If you are running our lightning fast servers, our support team is at your disposal for any questions you may have.