Written by: Geoffrey Callaghan

Firebase Hosting Tutorial

Firebase Hosting Tutorial

Firebase Hosting is a platform provided by Google Firebase that allows you to quickly and easily deploy web apps, static content, and dynamic content to a global content delivery network (CDN). Here’s a tutorial to help you get started:

  1. Set Up a Firebase Project:

    • Go to the Firebase console (console.firebase.google.com) and sign in with your Google account.
    • Click on “Add project” and follow the prompts to create a new Firebase project.
    • Once your project is created, click on it to access the project dashboard.
  2. Install Firebase CLI:

    • If you haven’t already, install the Firebase CLI (Command Line Interface) globally on your machine using npm:
      npm install -g firebase-tools
    • Once installed, you can use the firebase command in your terminal.
  3. Initialize Firebase Project:

    • In your terminal, navigate to the root directory of your web project.
    • Run the following command to initialize Firebase in your project:
      firebase init
    • Follow the prompts in the terminal to select Firebase Hosting as the feature you want to set up.
    • Choose your Firebase project from the list of existing projects or create a new one.
  4. Set Up Firebase Hosting:

    • During the initialization process, you’ll be asked to specify the directory where your web app files are located. This is typically the public or dist directory.
    • Firebase will generate a firebase.json file in your project directory with the hosting configuration.
  5. Deploy Your Web App:

    • Once Firebase Hosting is set up, you can deploy your web app by running the following command in your terminal:
      firebase deploy
    • Firebase will upload your web app files to its servers and deploy them to a global CDN.
    • After the deployment is complete, Firebase will provide you with a hosting URL where your web app is live.
  6. Custom Domain (Optional):

    • If you have a custom domain, you can connect it to your Firebase Hosting project.
    • In the Firebase console, go to the “Hosting” section and click on “Add custom domain”.
    • Follow the instructions to verify ownership of your domain and set up DNS records.
  7. Additional Features:

    • Firebase Hosting integrates seamlessly with other Firebase services such as Firestore (for database), Authentication, Cloud Functions, and more.
    • You can leverage these services to add dynamic functionality to your web app.
  8. Continuous Deployment:

    • You can set up continuous deployment with Firebase Hosting by connecting it to your Git repository.
    • Firebase will automatically deploy changes whenever you push to your repository.

That’s it! You’ve now successfully deployed your web app using Firebase Hosting. It’s a straightforward process that provides fast and reliable hosting for your web projects.