Use the Firebase SDK for Cloud Functions
masterThe firebase-functions package allows you to define Cloud Functions that run in a hosted, private, and scalable Node.js environment. You can write code that responds to events from various Firebase services (like Realtime Database, Firestore, or Authentication) and invokes functionality exposed by the Firebase platform.
To use the SDK, you import specific event triggers from sub-modules (e.g., firebase-functions/database) and use the logger module for structured logging.
// functions/index.js
const { onValueCreated } = require("firebase-functions/database");
const logger = require("firebase-functions/logger");
const notifyUsers = require("./notify-users");
exports.newPost = onValueCreated({ ref: "/posts/{postId}" }, (event) => {
logger.info("Received new post with ID:", event.params.postId);
return notifyUsers(event.data.val());
});