Deploy React on Netlify

When building an application with React, we often ask how to make our application online. In this context our React application.

There are many ways to deploy React application, but this article will cover the Netlify way.

Honestly, you can deploy yo…


This content originally appeared on DEV Community and was authored by M. Akbar Nugroho

When building an application with React, we often ask how to make our application online. In this context our React application.

There are many ways to deploy React application, but this article will cover the Netlify way.

Honestly, you can deploy your application on VPS even on a shared host, but they have trades off like you need to manually setup the CI/CD and other tools which sounds scary.

Netlify comes with built-in CI/CD and other useful tools to make our application easy to deploy. We just need to push our code into cloud repository like GitHub or GitLab and Netlify does the rest until our application online.

Enough for the introduction, let's start it out!

Requirements

  1. GitHub account (sign-up here)
  2. Netlify account (sign-up here)
  3. Git
  4. NodeJS

Setup - React.js project

I assume you have registered on GitHub and Netlify. We'll not create an entire app instead we just create simple app using CRA.

On your working directory, type npx create-react-app example-app to install our application. Then, let's verify our application is successfully installed using this command npm start.

Open http://localhost:3000 in your preferred browser. If you see something like image below, it's mean we're ready to go.

React.js success installation

Setup - GitHub

Maybe you have a question "why we need GitHub?", right?.

So, we need GitHub to host our project and trigger Netlify to build our site and make it online whenever we push a new feature or changes into our repository.

Now let's upload our application to GitHub!

First, we need to create a new public or private repository. After that copy the repository URL.

Note:
The repository URL has two types. HTTPS and SSH. HTTP requires you to insert GitHub username and password every time you push changes. Where SSH requires you to setup SSH-Key between your computer and GitHub.

Read this documentation to setup your SSH-Key.

cd to example-app and type commands below:

git remote add origin git@github.com:natively-project/example-app.git
git push -u origin main

Setup - Netlify

Now, login to your Netlify account and create new site.
Netlify create new site button
Choose GitHub.
Upload from GitHub

Choose the repository. In this case example-app.
Choose GitHub repository

Make sure you provide the right value on each field.

Branch to deploy is the branch (on GitHub) that Netlify will pull, build and publish our application. It's commonly your production branch.

Build command is a command that Netlify will execute to build our application.
Setup Netlify build

If you sure with your settings, then click the Deploy site button to start build and publish our application.

You will redirected and see something like image below.
Netlify builds the site

Wait until the process done. By default Netlify will give our application a unique subdomain, but we can change it on Domain settings.
Site is deployed

Click Options and select Edit site name.
Edit site name

Change your site name and save.
Choose site name

Now, let's visit our application!

Open your site name in your preferred browser. In this case my application name is example-app.netlify.app.

app is online

Congrats! we successfully deployed our application on Netlify.


This content originally appeared on DEV Community and was authored by M. Akbar Nugroho


Print Share Comment Cite Upload Translate Updates
APA

M. Akbar Nugroho | Sciencx (2021-08-12T01:03:53+00:00) Deploy React on Netlify. Retrieved from https://www.scien.cx/2021/08/12/deploy-react-on-netlify/

MLA
" » Deploy React on Netlify." M. Akbar Nugroho | Sciencx - Thursday August 12, 2021, https://www.scien.cx/2021/08/12/deploy-react-on-netlify/
HARVARD
M. Akbar Nugroho | Sciencx Thursday August 12, 2021 » Deploy React on Netlify., viewed ,<https://www.scien.cx/2021/08/12/deploy-react-on-netlify/>
VANCOUVER
M. Akbar Nugroho | Sciencx - » Deploy React on Netlify. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/12/deploy-react-on-netlify/
CHICAGO
" » Deploy React on Netlify." M. Akbar Nugroho | Sciencx - Accessed . https://www.scien.cx/2021/08/12/deploy-react-on-netlify/
IEEE
" » Deploy React on Netlify." M. Akbar Nugroho | Sciencx [Online]. Available: https://www.scien.cx/2021/08/12/deploy-react-on-netlify/. [Accessed: ]
rf:citation
» Deploy React on Netlify | M. Akbar Nugroho | Sciencx | https://www.scien.cx/2021/08/12/deploy-react-on-netlify/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.