Search⌘ K
AI Features

Develop the New Service Placeholder

Explore how to develop a new event-driven service in Firebase using Cloud Functions. Understand how to structure your code with meaningful names and nested directories, export functions effectively, and test locally without modifying your web application. This lesson guides you through building modular, independent services triggered by Firestore events.

Firebase expects all functions we develop to be exported from the services/web/firebase/functions/src/index.ts module. Currently, we have the “helloWorld” named export, which creates a Cloud Function service called helloWorld. We will have to export all our new services from that file as well.

A few words about naming conventions:

Names must be meaningful and self-explanatory, so that anyone who reads the code understands what they mean. This means less cognitive load on anyone involved and far fewer questions along the lines of “What’s the name of that service that cross-posts a blog post to dev.to, again? Oh, and where can I find its source code?”

So, instead of calling our service goldfish.ts or even cross-post-service.ts, which do not tell us how they were triggered, we are going to create the following service:

services/web/firebase/functions/src/firestore/posts/oncreate/ cross-post-to-devto/index.ts

Without opening the file and reading a line of code, it is immediately clear to anyone when this service is called and what it does. Although our service only contains one file, we will create a directory so that ...