If you’re on Windows, which I think many of you will be, you will go to the NodeJS website to download the installer. You’re going to install LTS because it’s more stable, and I feel safer using that for production. If you want to check out the latest features you can install current, but for this tutorial we’re going use LTS. Download the Windows Installer, either a 32-bit or 64-bit. I believe 32 bit processors are no longer in production (I could be wrong), so you’re most likely going to download the 64-bit version.
If you’re on Windows, the way you can verify which version you need is to right click on the Windows icon and click on System. It will say 32-bit or 64-bit. If you have a 64-bit system you can download the 64-bit version. Otherwise, install the 32-bit version. You’re going to click on the download button and it’s going to download the .msi file. The installation process is very straightforward. By default, the installer is going to add the Node library to the PATH. This is important.
Now the next thing we’re going to need to install is Visual Studio Code. Click and download it for Windows. It’s going to download an installer file, you can click keep, and then you’re going to run that. The process is exactly the same, you’re going to hit next, next, next, and it’s going to install Visual Studio to your system.
The next thing we’re going to install is React itself. You can install React through npm. Go ahead and open powershell, terminal, depending on your host system. If the following commands do not work and you have already installed the prerequisite software, go ahead and open up a new instance. It will load in the new PATH variables and it will be be able to find the Node and npm libraries. Now there are two ways to install Node libraries. You can install it globally to the system, which means you can use it in any directory. It’s not part of a project, it’s not a project dependency, it’s just an application that you’ve installed to your computer using Node. That is the method we’re going to use, npm install -g and then the package name. That is the syntax for installing global packages. If you’re in a projects directory that does have a package.json file, that means it’s a node project. So, you can install directly into that project. We’ll get more into that later. For right now, go ahead and type in the following command and hit enter:
npm install -g create-react-app
This process will take a few minutes to complete.
So this means now that from the command line we can use the command create-react-app. And that’s exactly what we’re going to do. Let’s also create a directory for our projects. I will create my project directory in the users directory on Windows. You should see pictures, music, downloads, etc. Just create a new directory, a new folder, and call it projects.
We’re also going to install React Developer Tools for Chrome. If you’re not using Chrome this is highly advised, install Chrome. You can go to chrome.google.com, install Chrome and then Google for React Developer Tools. You’re going to find that this package is offered by Facebook, click Add to Chrome. We’ll get more into what this does later on, however now is a great time to install it.
So what we’re going to do is change directory to projects, and then we’re going to issue the command create-react-app demo. This will create the directory that will host our React project. So in this instance, it’s going to be named demo.
In the next video we’re going to be looking at the basic project structure in React.
The format of this course will be be a bit different from courses that I have instructed in the past. Rather than begin by covering data types, syntax, etc, we will focus on coding demonstrations. It is my belief that you learn best by doing. We will begin with a few basic examples and then move on to writing fully functional applications.
So, traditionally when you have a client side application, for instance a React application that communicates with an API, it’s kind of like a ping pong request. You send a request and you receive a response. It’s kind of like a one for one. With a WebSocket you can keep clients connected on the server side, and you can send data to the client whenever it’s deemed necessary. So to demonstrate this capability, we’re going to be building a chat application. Users will be able to create an account, search for other users and add them and then message back and forth with them.
You’re going to learn how to use React and React Redux. You will learn how to use LoopbackJS, which is the rest API framework that we’re gonna use, which is built on top of Express. You’re also going to learn how to install packages through the Node package manager. Node is the environment that we can use to run server side applications like React’s hot load server, which is a way that we can run React in development. When we make changes to files it will automatically reload the page in our browser. So it makes development extremely simple. We’re also going to learn about WebSockets.
WebSockets, again, are a way that we can add bi-linear communication. The server can keep connections open indefinitely, and send messages to clients, and it can keep a running list as well. Now the package that we’re going to be using for it is called socket.io. You install it to your computer, however there isn’t any third party communication between any services. This gives us everything we need to make WebSockets work out of the box. I believe this technology was fully enabled in browsers in 2010. So it’s already 10 years old. But when we talk about technologies like PHP and whatnot, it’s relatively new.