Hosting a React Application Using Firebase: A Comprehensive Guide

Thilakshan Kathiramalai
3 min readJun 25, 2024

--

In today’s fast-paced development environment, hosting your web application needs to be efficient, reliable, and scalable. Firebase Hosting offers all these features and more, making it an excellent choice for deploying your web applications. In this article, we will walk you through the process of hosting a React application using Firebase.

Prerequisites

Before we get started, ensure you have the following installed on your local machine:

  • Node.js and npm
  • Firebase CLI
  • A React application created using Create React App

Step 1: Create a React Application

First, create a React application if you haven’t already:

npx create-react-app my-react-app
cd my-react-app

Step 2: Install Firebase Tools

If you haven’t installed Firebase CLI tools yet, you can do so using npm:

npm install -g firebase-tools

Step 3: Initialize Firebase in Your Project

Login to Firebase using the CLI:

firebase login

This command will open a browser window where you can log in with your Google account.

Next, initialize Firebase in your React project directory:

firebase init

You will be presented with a series of prompts. Here’s how to navigate them:

  1. Select Firebase features: Choose “Hosting: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys” by pressing the space bar and then pressing Enter.
  2. Associate with Firebase project: Select “Create a new project”.
  3. Specify project ID: Provide a unique project ID (e.g., my-sample-project).
  4. Project name: Optionally, provide a project name or press Enter to use the default.
  5. Public directory: Set the public directory to build.
  6. Single-page app: Configure as a single-page app by typing y (yes).
  7. Set up automatic builds and deploys with GitHub: Choose n (no) for now, unless you want to set up CI/CD with GitHub Actions.

Step 4: Build Your React Application

Before deploying, you need to create an optimized production build of your React app:

npm run build

This will create a build directory with your optimized application.

Step 5: Deploy to Firebase

Deploy your application to Firebase Hosting by running:

firebase deploy

Step 6: Access Your Hosted Application

After deployment, the Firebase CLI will provide a URL where your hosted app is accessible. You can visit this URL to see your React application live.

Troubleshooting Tips

  • Project ID Errors: Ensure the project ID is unique and adheres to Firebase’s naming conventions (6–30 characters, lowercase, numbers, and hyphens).
  • Permissions Issues: Verify that your Google account has the necessary permissions to create projects and deploy to Firebase.
  • Billing Setup: Ensure you have a billing account set up in Google Cloud Platform if required for advanced features.

Conclusion

Firebase Hosting provides a seamless way to deploy web applications with minimal setup. By following the steps outlined in this guide, you can quickly deploy your React application and take advantage of Firebase’s robust hosting infrastructure. Happy coding!

Feel free to leave a comment if you have any questions or run into any issues while setting up Firebase Hosting for your React application.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Thilakshan Kathiramalai
Thilakshan Kathiramalai

No responses yet

Write a response