React - Js Setup Guide For MacOS
React - Js Setup Guide For MacOS
Install VS Code
Introduction
This guide will cover a step-by-step guide for setting up a React.js development
environment on macOS. We will walk through steps for installing React.js as well as
necessary tools such as a text editor, Node.js, and Git. By the end of this guide, you
will have a development environment ready to begin writing your first React app!
Caution
This guide will not cover React.js development or how to write React code.
React development and web development in general can be done using a variety of
tools that depend on the project. The setup shown here will allow you to begin
working with React. However, other technologies are required if you intend to write
a backend, perform routing, etc. Such instructions are out of the scope of this guide.
What is React?
Before we begin, it's important to understand what React is. React is a frontend
JavaScript library for building user interfaces with reusable components. It allows
developers to create large web applications that can change data without reloading
the page. React is maintained by Facebook and a community of individual
developers.
Equipment and Requirements
This guide assumes that you have basic software development skills but does not
require that you be well versed with React or web development.
● 4+ GB memory
● 10+ GB storage
● macOS computer running version 10.10 or later
Step 1 Install Node.js and npm
What is Node.js?
What is npm?
Git is the most commonly used version control system. It tracks the changes you
make to files, so you have a record of what has been done, and you can revert back to
specific versions if something goes wrong. Git also makes collaboration easier,
allowing changes by multiple people to all be merged into one source.
Download Git Installer
Visit the Git downloads page here. Click “Download Latest Version”
Install Git
Run the Git installer pkg file and click “Continue” then “Install”
Install Git
Similar to before, you will be prompted to input your user credentials. Then click
“Install Software”. After installation, verify by running git --version on the
command line
Step 3 Install VS Code
What is VS Code?
VS Code is a lightweight text editor that also has some IDE features. It is developed
by Microsoft and has a variety of plugins to make working with various file types
easier.
This guide will use VS Code but you may choose a different text editor if you prefer -
the core functionality will be the same.
Install VS Code
Visit the VS Code downloads page here. Click “Download Visual Studio Code”
Install VS Code
Run the downloaded VS Code installer. The VS Code icon will appear on the desktop.
Drag it to the Applications folder in Finder.
Step 4 create-react-app
What is create-react-app?
This command installs a node package (or “module”) using npm. The -g flag means it
will install globally, so you always have access to it on the command line.
● Installing a package without the -g flag means it will only be accessible by the
project it was installed in
create-react-app
Running create-react-app
in the VS Code terminal
create-react-app
Now, we can use create-react-app to set up our React project. Navigate to the
directory where you want the project in the terminal and run the following with your
application name:
Note: npx is a package included with npm that runs other packages.
Step 5 Build React App
Once that’s done, navigate to the
project and start it with npm:
cd my-app
npm start
Build React App
Afterward, a localhost tab will open in your browser. If not, type localhost:3000 into
the browser. (The port number may also be 8080, verify in the terminal output). The
page should look like this:
Build React App
What happened?
This is the starter code that create-react-app built! npm start builds the project. As
you make and save changes, the project will automatically be rebuilt to reflect those
changes.
For example, open App.js in VS Code. You will notice that the text on line 10 is what
we see on the localhost page. Modify this text to whatever you want. You will notice
that once you save the file, the project will be recompiled on the terminal.
Build React App
Notice the changed text
Step 6 Push Changes to Git
git init
git add .
● Specifies that all new or modified files (in this case every file in the project) will
be added to the repository
● Specify the main branch of the repository (read more about git branching here)
● Get this URL from the new repo instructions mentioned on slide 31. This
specifies which repository our project will be backed by
● “Push” (or save) our project to the main branch of our GitHub repository
Push Changes to Repository
As a next step, if you would like to learn React, the official guide is an excellent
resource.
Troubleshooting - Working Tree Clean
If you get an error when trying to commit your project to GitHub such as “Nothing to
commit, working tree clean” then git has not recognized that files have been
changed.