How to Set Up Firebase with a Web Application

How to Set Up Firebase with a Web Application – Step-by-Step Guide

This guide walks you through the complete process of integrating Firebase into a basic web app using CDN links and Firebase console setup.


🔹 Step 1: Create a Firebase Project

  1. Go to https://firebase.google.com

  2. Click on "Get Started" or "Go to Console"

  3. Click "Add Project"

  4. Name your project:
    👉 Dean-Project

  5. Click Continue

  6. Enable Google Analytics (toggle ON)

  7. Click Continue

  8. Choose Default Account for Firebase

  9. Click Create Project

🔄 Firebase will now take a few moments to set up your project.

  1. Once complete, click Continue



🔹 Step 2: Register Your Web App

  1. In Firebase Console, go to Project Overview

  2. Click on the Web icon (</>) to register a web app

  3. Enter your app name:
    👉 Ry-app

  4. ❌ Do not check "Also set up Firebase Hosting"

  5. Click Register App

  6. Firebase will now generate a JavaScript snippetCopy this code

  7. Click Continue to Console


🔹 Step 3: Set Up Firebase in Your Web App

  1. In VS Code, create a new project folder:

    mkdir firebase
    cd firebase
    
  2. Create a file:
    👉 index.html
    👉 index.js


🔹 Step 4: Add Firebase SDK via CDN

To use Firebase features, include the CDN version of Firebase SDK.

  1. Go to:
    https://firebase.google.com/docs/web/setup

  2. Scroll to "Add Firebase SDKs via CDN"

  3. Copy the required libraries:

<!-- Firebase App (core SDK) -->
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js"></script>

<!-- Add other Firebase services you want to use -->
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-firestore.js"></script>

🔹 Step 5: Add Firebase Config in HTML

Paste the config script you got during registration in the <body> tag or inside your index.js:

<script>
  const firebaseConfig = {
    apiKey: "YOUR_API_KEY",
    authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
    projectId: "YOUR_PROJECT_ID",
    storageBucket: "YOUR_PROJECT_ID.appspot.com",
    messagingSenderId: "SENDER_ID",
    appId: "APP_ID"
  };

  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
</script>

✅ Example: Simple Project Structure

firebase/
├── index.html
└── index.js

✅ Example: index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Firebase Demo</title>
</head>
<body>

  <h1>Welcome to Firebase Web App</h1>

  <!-- Firebase SDKs -->
  <script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/10.12.2/firebase-auth.js"></script>

  <script>
    const firebaseConfig = {
      apiKey: "YOUR_API_KEY",
      authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
      projectId: "YOUR_PROJECT_ID",
      storageBucket: "YOUR_PROJECT_ID.appspot.com",
      messagingSenderId: "SENDER_ID",
      appId: "APP_ID"
    };

    firebase.initializeApp(firebaseConfig);
  </script>

</body>
</html>

🔹 Next Step: Use Firebase Services

You can now start using Firebase features like:

firebase.auth()
firebase.firestore()

You’re all set up to build Firebase-powered apps using HTML and JavaScript. Let me know if you want to add Firebase Authentication, Firestore Database, or Hosting next.

Comments

Popular posts from this blog

How to Upload Your Local Project to GitHub Properly

YouTube Videos, Translation, AI Tools Aur Hindi Mein Dekhne Ka Experience

How to Build a Telegram Bot Using Node.js – Step-by-Step Guide