Firebase is Google's app platform, and most devs only scratch the surface with Auth and Firestore. Its JavaScript SDK exposes powerful APIs for real-time data, storage, ML, and more.
Firestore Real-Time Listeners
import { collection, query, where, onSnapshot, orderBy, limit } from "firebase/firestore";
const q = query(
collection(db, "scrapedProducts"),
where("price", "<", 50),
orderBy("scrapedAt", "desc"),
limit(100)
);
const unsubscribe = onSnapshot(q, (snapshot) => {
snapshot.docChanges().forEach((change) => {
if (change.type === "added") console.log("New product:", change.doc.data());
if (change.type === "modified") console.log("Price changed:", change.doc.data());
if (change.type === "removed") console.log("Removed:", change.doc.id);
});
});
Real-time sync across all connected clients — zero WebSocket setup.
Firestore Aggregation Queries
import { getAggregateFromServer, collection, query, where, sum, average, count } from "firebase/firestore";
const snapshot = await getAggregateFromServer(
query(collection(db, "products"), where("category", "==", "electronics")),
{
totalPrice: sum("price"),
avgPrice: average("price"),
count: count()
}
);
console.log("Total:", snapshot.data().totalPrice);
console.log("Average:", snapshot.data().avgPrice);
console.log("Count:", snapshot.data().count);
Cloud Functions Callable API
// Client side
import { getFunctions, httpsCallable } from "firebase/functions";
const functions = getFunctions();
const scrapeUrl = httpsCallable(functions, "scrapeUrl");
const result = await scrapeUrl({ url: "https://example.com", selectors: ["h1", ".price"] });
console.log(result.data); // { title: "...", price: "$29.99" }
Firebase Storage: Resumable Uploads
import { ref, uploadBytesResumable, getDownloadURL } from "firebase/storage";
const storageRef = ref(storage, `exports/${userId}/${filename}`);
const uploadTask = uploadBytesResumable(storageRef, file);
uploadTask.on("state_changed",
(snapshot) => {
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
console.log(`Upload: ${progress}%`);
},
(error) => console.error(error),
async () => {
const url = await getDownloadURL(uploadTask.snapshot.ref);
console.log("Download URL:", url);
}
);
Firebase Auth: Beyond Email/Password
import { signInWithPopup, GoogleAuthProvider, linkWithCredential, EmailAuthProvider } from "firebase/auth";
// Sign in with Google
const result = await signInWithPopup(auth, new GoogleAuthProvider());
// Link additional email/password to same account
const credential = EmailAuthProvider.credential(email, password);
await linkWithCredential(result.user, credential);
// Custom claims (admin-only)
const token = await result.user.getIdTokenResult();
if (token.claims.admin) showAdminPanel();
Remote Config: A/B Testing API
import { fetchAndActivate, getValue } from "firebase/remote-config";
await fetchAndActivate(remoteConfig);
const showNewFeature = getValue(remoteConfig, "show_new_scraper_ui").asBoolean();
const maxResults = getValue(remoteConfig, "max_scrape_results").asNumber();
Feed Firebase with scraped data? My Apify tools export directly to Firestore and Cloud Storage.
Custom Firebase data pipeline? Email spinov001@gmail.com
Top comments (0)