Books/Firebase Essentials/Setting Up a Firebase Project

    Setting Up a Firebase Project

    Setting Up a Firebase Project

    Let's get your Firebase project created and ready to use. This is a one-time setup that takes about 10 minutes.

    Step 1: Create a Firebase Project

    1. Go to the Firebase Console: console.firebase.google.com
    2. Sign in with your Google account
    3. Click "Create a project" (or "Add project")
    4. Enter a project name (e.g., "my-first-app")
    5. Optionally enable Google Analytics (you can skip this for now)
    6. Click "Create project"

    Wait a moment, and your project is ready!

    Step 2: Explore the Firebase Console

    The Firebase Console is your dashboard for managing everything. Here's what you'll find:

    SectionWhat It Does
    Project OverviewHome page with usage stats
    AuthenticationManage users and sign-in methods
    Firestore DatabaseView and manage your data
    StorageView uploaded files
    HostingSee your deployed sites
    FunctionsView and manage cloud functions

    Take a moment to click around. The console is where you'll go to check your data, manage users, and troubleshoot issues.

    Step 3: Register a Web App

    Firebase needs to know what kind of app you're building. To get your configuration:

    1. In the Firebase Console, click the gear iconProject settings
    2. Scroll down to "Your apps"
    3. Click the web icon (</>) to add a web app
    4. Give it a nickname (e.g., "My Web App")
    5. Optionally check "Also set up Firebase Hosting"
    6. Click "Register app"

    You'll see a configuration object — this is important! It looks like this:

    const firebaseConfig = {
      apiKey: "AIzaSyD...",
      authDomain: "my-first-app.firebaseapp.com",
      projectId: "my-first-app",
      storageBucket: "my-first-app.firebasestorage.app",
      messagingSenderId: "123456789",
      appId: "1:123456789:web:abc123"
    };

    Save this config — you'll need it when connecting your app. You can always find it again in Project Settings.

    What to ask your AI: "I have my Firebase config. Help me set up environment variables so I don't hardcode these values."

    Is the API Key a Secret?

    A common question! Firebase API keys are not secret in the traditional sense. They identify your project but don't grant access to data by themselves. Firestore Security Rules control who can read/write data.

    That said, it's still good practice to use environment variables rather than hardcoding them.

    Step 4: Enable Firestore

    Firestore isn't enabled by default. Let's turn it on:

    1. In the Firebase Console, click "Firestore Database" in the left sidebar
    2. Click "Create database"
    3. Choose a location (pick one close to your users — you can't change this later)
    4. Choose "Start in test mode" for now (this allows all reads/writes — we'll secure it later)
    5. Click "Enable"

    Your database is now ready!

    Important: Test mode allows anyone to read/write your data for 30 days. This is fine for learning, but you'll need to update your security rules before launching a real app.

    What to ask your AI: "Help me write Firestore security rules that only allow authenticated users to read and write their own data."

    Step 5: Install the Firebase CLI

    The Firebase CLI lets you deploy, manage, and test from your terminal.

    Install

    npm install -g firebase-tools

    Login

    firebase login

    This opens your browser for Google authentication. Once logged in, the CLI is connected to your account.

    Verify

    firebase projects:list

    You should see your project in the list.

    Step 6: Initialize Firebase in Your Project

    Navigate to your project folder and run:

    firebase init

    This interactive wizard lets you choose which Firebase services to set up. Use the arrow keys and spacebar to select:

    • Firestore — Database rules and indexes
    • Hosting — For deploying your web app
    • Functions — If you need server-side code
    • Storage — If you need file uploads

    For each service, it'll ask configuration questions. The defaults are usually fine for beginners.

    What Gets Created

    After firebase init, you'll see new files:

    my-project/
    ├── .firebaserc           # Links to your Firebase project
    ├── firebase.json         # Firebase configuration
    ├── firestore.rules       # Database security rules
    ├── firestore.indexes.json # Database indexes
    └── ... your app files
    

    What to ask your AI: "I ran firebase init. Can you explain what each generated file does?"

    Step 7: Install the Firebase SDK

    In your project directory, install the Firebase JavaScript SDK:

    npm install firebase

    This is the client-side library your app uses to communicate with Firebase services.

    For backend/server-side code (like seed scripts or Cloud Functions), you'll also need:

    npm install firebase-admin
    PackageUse Case
    firebaseFrontend (React, Vue, etc.) — runs in the browser
    firebase-adminBackend (Node.js scripts, Cloud Functions) — runs on a server

    Quick Setup Checklist

    Here's everything you need, in order:

    ✅ Create Firebase project at console.firebase.google.com
    ✅ Register a web app and copy the config
    ✅ Enable Firestore (test mode is fine for learning)
    ✅ Install Firebase CLI: npm install -g firebase-tools
    ✅ Login: firebase login
    ✅ Initialize in your project: firebase init
    ✅ Install SDK: npm install firebase
    

    What's Next?

    Your Firebase project is set up! Next, we'll dive into Firestore — learning how to store, read, update, and delete data in your database.

    What to ask your AI: "I've set up my Firebase project. Now help me create my first Firestore collection and add some data."


    🌐 www.genai-mentor.ai