---
name: firebase-cloud-functions-boilerplate
description: "Scaffolds a ready-to-deploy Firebase Cloud Function for the trigger and SDK version you pick, with typed handlers, error handling and comments. Use when a developer needs a starter Firebase Cloud Function for a given trigger type, language and SDK version. Do not use for reviewing Firestore security rules or running a full backend design. Related topics: firebase, coding, cloud."
---

# Firebase Cloud Functions Boilerplate

Scaffolds a ready-to-deploy Firebase Cloud Function for the trigger and SDK version you pick, with typed handlers, error handling and comments.

## When to use

Use this skill when a developer needs a starter Firebase Cloud Function for a given trigger type, language and SDK version. Do not use it for reviewing Firestore security rules or running a full backend design.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Pick the import and trigger API that matches the chosen SDK version and language.
3. Write the handler signature the trigger requires and implement the described logic.
4. Add try and catch with the right error type for the trigger, if requested.
5. Provide the export, the deploy command and one local emulator test note.

## Inputs

- **Function name** (free text, e.g. "sendWelcomeEmail")
- **Trigger type** (choose one: HTTPS Callable, HTTP Request (REST), Firestore Trigger, Auth Trigger, Pub/Sub Scheduled)
- **Language** (choose one: JavaScript, TypeScript)
- **What the function does** (longer free text)
- **Firebase SDK version** (choose one: v2 (Modular), v1 (Legacy))
- **Include error handling with try and catch** (choose one: Yes, No)

## Output

The complete function file in a single code block with comments, followed by the deploy command and a short emulator test note.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Firebase Cloud Function Scaffold

Write the starting code for one Firebase Cloud Function in Node.js.

- Function name: {{Function name}}
- Trigger type: {{Trigger type}}
- Language: {{Language}}
- What the function does: {{What the function does}}
- Firebase SDK version: {{Firebase SDK version}}
- Include error handling with try and catch: {{Include error handling with try and catch}}

Use the import style and trigger API that belongs to the chosen SDK version, so v2 uses the modular firebase-functions/v2 entry points. Match the signature to the trigger: callables take request data and return a value or throw an HttpsError, HTTP handlers send a status code, Firestore and Auth triggers read the event payload. Keep secrets out of the source and read them through environment config or Secret Manager. Include the export line and, when relevant, region and memory options.

Output the full function file with comments, then the deploy command and one note on how to test it locally with the emulator.

## Pitfalls

- Mixing v1 imports with v2 handler signatures, which fails at deploy time.
- Hardcoding API keys in the source instead of using secrets.
- Returning plain objects from an HTTP handler without sending a response, so the request hangs.
