iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Intro

Firebase is Googles app platform: managed auth, Firestore, Cloud Functions, Hosting, Analytics, and more. Built for shipping mobile + web fast.

Firebase — what it is

EXAMPLE
// ===== The values =====
// - Auth: email, Google, Apple, GitHub, anonymous, phone
// - Firestore: realtime NoSQL with offline support
// - Realtime Database: simpler JSON tree (legacy but still used)
// - Functions: serverless triggers + HTTP
// - Hosting: CDN for static + dynamic
// - Storage: file storage
// - Analytics, Remote Config, A/B testing, Crashlytics

// ===== Hello, Firestore =====
import { initializeApp } from 'firebase/app';
import { getFirestore, doc, setDoc, getDoc, onSnapshot } from 'firebase/firestore';

const app = initializeApp({ /* firebaseConfig from console */ });
const db  = getFirestore(app);

await setDoc(doc(db, 'users', 'u-1'), { name: 'Alex', email: 'a@x.io' });
const snap = await getDoc(doc(db, 'users', 'u-1'));
console.log(snap.data());

onSnapshot(doc(db, 'users', 'u-1'), (s) => console.log('live:', s.data()));

// ===== Auth =====
import { getAuth, signInWithEmailAndPassword, onAuthStateChanged } from 'firebase/auth';
const auth = getAuth(app);
await signInWithEmailAndPassword(auth, 'a@x.io', 'pw');
onAuthStateChanged(auth, (user) => console.log(user?.uid));

// ===== Security rules (Firestore) =====
rules_version = '2';
service cloud.firestore {
  match /databases/{db}/documents {
    match /users/{uid} {
      allow read, write: if request.auth != null && request.auth.uid == uid;
    }
  }
}

// ===== Cloud Functions =====
import * as functions from 'firebase-functions';
export const onUserCreate = functions.firestore
  .document('users/{uid}')
  .onCreate(async (snap, ctx) => {
    // send welcome email, etc.
  });

// ===== When Firebase wins =====
// - Mobile + web MVPs that need auth + persistence in a day
// - Realtime collaborative features
// - Startups that want to spend zero time on backend ops
// - Add Crashlytics + Analytics for free instrumentation

// ===== When Firebase hurts =====
// - Complex relational data
// - Heavy querying with multiple WHERE + ORDER BY combos (composite indexes pile up)
// - Cost predictability at scale (per-read / per-write pricing surprises)
// - Lock-in to Google Cloud

// ===== Patterns to internalise =====
// - Security rules from day one (test-mode is for dev only)
// - Denormalise for the read pattern; this is NoSQL
// - serverTimestamp() over client clocks
// - Emulator suite for local dev + CI

// ===== Pitfalls =====
// - Shipping with open rules ('allow read, write: if true')
// - Untyped writes from many clients -> inconsistent shapes
// - Listening to huge documents (split into smaller docs)
// - Hidden costs from too many onSnapshot listeners left attached

Why it matters

Firebase is the fastest path from idea to shipped app for small teams. Auth + Firestore + Hosting + Functions covers most product surfaces. The hidden cost is rules discipline and per-op pricing; spend time on those two and you keep the speed advantage while avoiding the classic Firebase regret stories.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Firebase = BaaS by Google.
// Auth + Firestore + Realtime DB + Storage + Functions + Hosting + FCM + Analytics.
Try it Yourself »

Exercise

Bootstrap the Firebase app.

const app = App(config);

Test yourself

Q1. Firebase is operated by…
Q2. Firebase is best described as…
Q3. The CLI is installed with…

Discussion

Loading…