In this tutorial, you will learn how to create a new React App and deploy it to Heroku cloud.
Heroku is a platform as a service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud.
Video
As usual, in this tutorial, we will learn how to create and deploy React App step by step.
Steps
Here are the steps:
1. Create React HelloWorld App
2. Host source code of React App on GitHub
3. Login to Heroku and create a new app in Heroku
4. Adding a buildpack
5. Connecting GitHub repository to Heroku app
1. Create React HelloWorld App
npx create-react-app react-app-heroku
cd react-app-heroku
import React, { Component } from 'react'; class App extends Component { render() { return ( <div className="App"> <h1>Hello World!</h1> </div> ); } } export default App;
npm start
Runs the app in development mode. Open http://localhost:3000 to view it in the browser.
2. Host Source Code of React App on GitHub
Here, we’ll be creating a fresh GitHub repository and pushing our app to it.
Login to your GitHub account and create a repository as "react-app-heroku".
You can use Git to push source code of newly created React App to this GitHub repository using the following commands:
git remote add origin <new_github_repository_url>
git add .
git commit -m "initial commit"
git push -u origin master
Now our app is on GitHub.
3. Login to Heroku and Create a New App in Heroku
Now it's time to login to Heroku to deploy our React app to Heroku cloud.
Go ahead and login to Heroku and create a new app like:
4. Adding a buildpack
5. Connecting GitHub repository to Heroku app
Next, navigate back to the Deploy tab. Scroll down to the deployment method section and choose GitHub.
Now you can choose any branch you want to deploy. For this example, I have selected the main branch.
Now you can click on the Deploy Branch button to initiate deployment. Heroku will start fetching and installing packages.
Once the deployment is finished, you will get an update that tells you that your app was successfully deployed on https://react-application-heroku-demo.herokuapp.com:
Comments
Post a Comment
Leave Comment