Firebase Realtime Database Guide
Firebase Realtime Database Guide
Realtime Database for Live Updates
Firebase Realtime Database app me instant data sync aur live updates provide karta hai, user experience smooth aur interactive banata hai.
import { getDatabase, ref, set } from "firebase/database"
import { app } from "./firebaseConfig"
const db = getDatabase(app)
set(ref(db, "users/1"), { name: "Ali", age: 25 })
Firestore for Scalable Data
Firestore flexible aur scalable database hai, jo structured data store karne aur query karne me easy aur fast banata hai.
import { getFirestore, doc, setDoc } from "firebase/firestore"
import { app } from "./firebaseConfig"
const db = getFirestore(app)
await setDoc(doc(db, "users", "1"), { name: "Zubair", role: "Developer" })
Firebase Authentication
Firebase Auth secure login aur signup methods provide karta hai, jaise email/password, Google aur social logins.
import { getAuth, signInWithEmailAndPassword } from "firebase/auth"
import { app } from "./firebaseConfig"
const auth = getAuth(app)
signInWithEmailAndPassword(auth, "user@example.com", "password123")
.then(user => console.log(user))
Cloud Functions for Backend Logic
Cloud Functions serverless backend logic implement karte hain, jaise notifications, triggers aur data processing.
import * as functions from "firebase-functions"
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello Firebase!")
})
Firebase Storage for File Handling
Firebase Storage secure file uploads aur media management provide karta hai, scalable aur fast delivery ke liye perfect hai.
import { getStorage, ref, uploadBytes } from "firebase/storage"
import { app } from "./firebaseConfig"
const storage = getStorage(app)
const fileRef = ref(storage, "images/photo.png")
await uploadBytes(fileRef, new Blob(["Hello"]))
Push Notifications with FCM
Firebase Cloud Messaging push notifications send karne aur user engagement increase karne ke liye use hota hai.
import { getMessaging, getToken } from "firebase/messaging"
import { app } from "./firebaseConfig"
const messaging = getMessaging(app)
const token = await getToken(messaging)
console.log("FCM Token:", token)
Realtime Database for Live Updates
Firebase Realtime Database app me instant data sync aur live updates provide karta hai, user experience smooth aur interactive banata hai.
import { getDatabase, ref, set } from "firebase/database"
import { app } from "./firebaseConfig"
const db = getDatabase(app)
set(ref(db, "users/1"), { name: "Ali", age: 25 })
Firestore for Scalable Data
Firestore flexible aur scalable database hai, jo structured data store karne aur query karne me easy aur fast banata hai.
import { getFirestore, doc, setDoc } from "firebase/firestore"
import { app } from "./firebaseConfig"
const db = getFirestore(app)
await setDoc(doc(db, "users", "1"), { name: "Zubair", role: "Developer" })
Firebase Authentication
Firebase Auth secure login aur signup methods provide karta hai, jaise email/password, Google aur social logins.
import { getAuth, signInWithEmailAndPassword } from "firebase/auth"
import { app } from "./firebaseConfig"
const auth = getAuth(app)
signInWithEmailAndPassword(auth, "user@example.com", "password123")
.then(user => console.log(user))
Cloud Functions for Backend Logic
Cloud Functions serverless backend logic implement karte hain, jaise notifications, triggers aur data processing.
import * as functions from "firebase-functions"
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello Firebase!")
})
Firebase Storage for File Handling
Firebase Storage secure file uploads aur media management provide karta hai, scalable aur fast delivery ke liye perfect hai.
import { getStorage, ref, uploadBytes } from "firebase/storage"
import { app } from "./firebaseConfig"
const storage = getStorage(app)
const fileRef = ref(storage, "images/photo.png")
await uploadBytes(fileRef, new Blob(["Hello"]))
Push Notifications with FCM
Firebase Cloud Messaging push notifications send karne aur user engagement increase karne ke liye use hota hai.
import { getMessaging, getToken } from "firebase/messaging"
import { app } from "./firebaseConfig"
const messaging = getMessaging(app)
const token = await getToken(messaging)
console.log("FCM Token:", token)
Firebase Hosting for Deployment
Firebase Hosting fast aur secure static site deployment aur CDN support provide karta hai, production apps ke liye ideal hai.
firebase init hosting
firebase deploy
Real-Time Listeners for Data Sync
Realtime listeners app ko live updates ke saath sync karte hain, jaise chat apps aur dashboards me required hai.
import { getDatabase, ref, onValue } from "firebase/database"
import { app } from "./firebaseConfig"
const db = getDatabase(app)
onValue(ref(db, "users/1"), snapshot => {
console.log(snapshot.val())
})
Role-Based Access Control
Firebase rules aur custom claims se user roles manage hote hain, aur app ke data ko secure rakha jata hai.
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}