Getting started overview

Getting started with Google Firebase focuses on quickly setting up a backend for web and mobile applications. The process involves creating a Firebase project, selecting and configuring services, and integrating client-side or server-side SDKs into your application. Firebase provides a suite of tools designed to simplify common development tasks, such as user authentication, data storage, and hosting, abstracting much of the server-side infrastructure management Firebase overview documentation.

This guide outlines the essential steps to create an account, establish a new project, obtain necessary credentials, and execute a foundational first request. Firebase offers a Spark Plan free tier with generous usage limits, making it accessible for initial development and small-scale projects.

Quick Reference: Firebase Getting Started

Step What to Do Where
1. Create Google Account Set up or use an existing Google account. Google Account signup page
2. Create Firebase Project Navigate to the Firebase console and add a new project. Firebase Console
3. Add App to Project Register your web, iOS, Android, or other app within the project. Firebase Console > Project Overview > Add App
4. Install SDK Integrate the Firebase SDK for your chosen platform. Platform-specific documentation (e.g., Firebase Web setup, Firebase iOS setup)
5. Initialize Firebase Add the configuration snippet to your application. Your application's main entry file
6. Make First Request Implement a basic interaction, such as writing data to Cloud Firestore. Your application's code

Create an account and get keys

1. Google Account Creation

Firebase services are integrated with Google Cloud Platform, requiring a Google account for access. If you do not have one, you can create a Google account here. Existing Google accounts, such as those used for Gmail or Google Drive, are sufficient.

2. Firebase Project Setup

  1. Access the Firebase Console: Navigate to the Firebase Console. You will be prompted to sign in with your Google account.
  2. Create a New Project: Click the "Add project" button.
  3. Project Naming: Provide a unique name for your project. This name is user-facing.
  4. Project ID Generation: Firebase automatically generates a unique Project ID. You can edit this ID if desired, but it must remain globally unique. The Project ID is used programmatically to identify your project.
  5. Google Analytics Integration: Optionally enable Google Analytics for your project. This is recommended for performance monitoring and user behavior insights Firebase Analytics documentation. If enabled, select an existing Analytics account or create a new one.
  6. Complete Project Creation: Click "Create project" to finalize. Firebase will provision the necessary resources.

3. Adding an App to Your Project

Once your project is created, you need to register an application (web, iOS, Android, Flutter, Unity, or C++) with it. This step generates the configuration details required to connect your app to Firebase services.

  1. Select Your Platform: From the Project Overview screen, click on the icon corresponding to your application's platform (e.g., "Web" for a web application, "iOS" for an Apple application).
  2. Register Your App: Follow the platform-specific instructions:
    • Web: Enter an App nickname (optional). Firebase provides a snippet containing your project's API Key and other configuration details.
    • iOS: Provide your Apple bundle ID, App Store ID (optional), and App nickname (optional). Download the GoogleService-Info.plist file, which contains your configuration.
    • Android: Enter your Android package name, App nickname (optional), and your SHA-1 debug signing certificate fingerprint (optional but recommended for services like Phone Authentication). Download the google-services.json file.
  3. Copy Configuration/Download File: Securely save the configuration snippet or the downloaded file (GoogleService-Info.plist or google-services.json). These contain your API key and other project-specific identifiers. For web applications, the configuration object itself contains the apiKey, authDomain, projectId, storageBucket, messagingSenderId, and appId Firebase Web setup instructions.

Your first request

This example demonstrates integrating Firebase into a web application and performing a basic write operation to Cloud Firestore, Firebase's NoSQL document database. This assumes you have already created a Firebase project and added a web app as described above. Before proceeding, ensure you enable Cloud Firestore in your Firebase project via the "Build > Firestore Database" section of the Firebase console.

1. Install Firebase SDK

For web applications, install the Firebase JavaScript SDK using npm:

npm install firebase

For other platforms, refer to the respective documentation (e.g., Firebase iOS SDK setup for Swift/Objective-C, Firebase Android SDK setup for Kotlin/Java).

2. Initialize Firebase in Your Application

In your JavaScript file (e.g., index.js or app.js), import and initialize Firebase using the configuration generated when you added your web app:

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore, collection, addDoc } from "firebase/firestore";

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "YOUR_API_KEY",
  authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
  projectId: "YOUR_PROJECT_ID",
  storageBucket: "YOUR_PROJECT_ID.appspot.com",
  messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
  appId: "YOUR_APP_ID",
  measurementId: "G-YOUR_MEASUREMENT_ID"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

console.log("Firebase initialized.");

Replace the placeholder values (YOUR_API_KEY, YOUR_PROJECT_ID, etc.) with your actual Firebase project configuration found in the Firebase Console by going to Project settings > General > Your apps. For iOS, you would add the GoogleService-Info.plist file to your Xcode project and configure Firebase in your AppDelegate iOS configuration details. Similarly, for Android, you would place google-services.json in your app module directory and configure Gradle Android configuration details.

3. Write Data to Cloud Firestore

Now, let's create a simple function to add a document to a Firestore collection:

async function addExampleDocument() {
  try {
    const docRef = await addDoc(collection(db, "messages"), {
      text: "Hello from Firebase!",
      timestamp: new Date()
    });
    console.log("Document written with ID: ", docRef.id);
  } catch (e) {
    console.error("Error adding document: ", e);
  }
}

// Call the function to add data
addExampleDocument();

When this code executes (e.g., when a button is clicked or on page load), Firebase will connect to Cloud Firestore and create a new document in a collection named messages. You can verify this by navigating to the "Firestore Database" section in your Firebase Console, where you should see the new collection and document. By default, Firestore security rules allow only authenticated users to read and write data. For initial testing, you might need to temporarily modify your Firestore security rules to allow unauthenticated writes while developing, but this is not recommended for production Firestore Security Rules overview.

Common next steps

After successfully performing your first request, consider these common next steps to expand your Firebase integration:

  • Configure Security Rules: Implement robust Firebase Security Rules for Cloud Firestore and Cloud Storage to protect your data. This is a critical step before deploying any application to production.
  • User Authentication: Integrate Firebase Authentication to manage users with various providers like email/password, Google, Facebook, and more.
  • Realtime Data: Explore the realtime capabilities of Cloud Firestore by setting up listeners that automatically update your application when data changes on the backend.
  • Cloud Functions: Write server-side code using Cloud Functions for Firebase to extend your backend with custom logic, trigger events, and interact with other Google Cloud services.
  • Hosting: Deploy your web application with Firebase Hosting, which offers fast, secure, and global content delivery with SSL by default.
  • Monitoring and Analytics: Utilize Firebase Analytics, Crashlytics, and Performance Monitoring to gain insights into app usage, stability, and performance.
  • Explore Other Services: Depending on your application's needs, investigate other Firebase products such as Cloud Storage for files, Remote Config for dynamic app updates, or Cloud Messaging for notifications.

Troubleshooting the first call

If your first Firebase API call encounters issues, consider the following troubleshooting steps:

  • Check Firebase Configuration: Ensure that the firebaseConfig object (for web) or the GoogleService-Info.plist/google-services.json file contains the correct values for your project. Mismatched API keys or project IDs are common errors. Double-check these against the "Project settings" in your Firebase Console.
  • Internet Connectivity: Confirm your device or development environment has a stable internet connection. Firebase services require network access.
  • Security Rules: For Cloud Firestore or Realtime Database, verify your security rules. By default, rules might be restrictive. For initial testing, you might set rules to allow unauthenticated reads/writes (e.g., allow read, write: if true;), but ensure to secure them before production deployment. Access and modify rules under "Build > Firestore Database > Rules" in the Firebase console.
  • Browser Console/IDE Output: Examine your browser's developer console (for web apps) or your IDE's output window (for mobile/desktop apps) for error messages. Firebase SDKs often provide detailed error descriptions. These can indicate issues like "Permission Denied" (security rules), "Invalid API Key", or network errors.
  • Firebase Console Logs: Check the "Functions" section in the Firebase Console for logs if you are using Cloud Functions and encountering issues there. For other services, specific dashboards might show errors or warnings.
  • SDK Version Mismatch: Ensure that the versions of Firebase SDKs you are using are compatible and up-to-date. Refer to the Firebase SDK release notes for the latest versions and compatibility.
  • CORS Issues (Web): If developing a web application and encountering Cross-Origin Resource Sharing (CORS) errors, ensure your Firebase environment or development server is configured correctly. Firebase Hosting generally handles CORS for you, but local development setups might require configuration.
  • Billing Account (Blaze Plan): If you are on the Blaze Plan and exceed free tier limits, ensure your Google Cloud billing account is correctly set up and active.