About firebase-functions
firebase-functions is a development-pattern skill for Firebase Functions projects, covering TypeScript function organization, error handling, and build and test steps. It is for developers maintaining Firestore-triggered functions and related backend code.
Key features
- 01Show function directory organization
- 02Provide a Firestore trigger example
- 03Describe an error-handling pattern
- 04List build and Jest test commands
Use cases
- 01Plan a Firebase Functions project structure
- 02Write a Firestore document-created trigger
- 03Handle errors in asynchronous function work
- 04Build functions and run tests
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ bumgeunsong/ daily-writing-friends --skill firebase-functionsAfter installing, type/firebase-functionsin Claude Code to confirm it loaded.
Details
From the project READMEFirebase Functions Patterns
Directory Structure
functions/
├── src/
│ ├── index.ts # Function exports
│ ├── admin.ts # Firebase Admin SDK init
│ ├── backfill/ # Data migration scripts
│ ├── commentSuggestion/ # AI comment features
│ ├── commentings/ # Comment activity tracking
│ ├── notifications/ # Push notification functions
│ ├── postings/ # Post activity tracking
│ ├── replyings/ # Reply activity tracking
│ └── shared/ # Shared utilities
Function Structure
import { onDocumentCreated } from 'firebase-functions/v2/firestore';
import admin from '../admin';
import { Post } from '../types/Post';
export const createPosting = onDocumentCreated(
'boards/{boardId}/posts/{postId}',
async (event) => {
const postData = event.data?.data() as Post;
const { boardId, postId } = event.params;
if (!postData) {
console.error('No post data found.');
return null;
}
try {
await admin.firestore()
.collection('users')
.doc(postData.authorId)
.collection('postings')
.add(postingData);
console.log(`Created posting for user ${postData.authorId}`);
} catch (error) {
console.error('Error writing posting:', error);
}
return null;
}
);
Error Handling
Don't throw - let function complete gracefully:
try {
await admin.firestore().collection('...').add(data);
console.log(`Successfully created ${resourceType}`);
} catch (error) {
console.error(`Error creating ${resourceType}:`, error);
// Don't throw - function should complete
}
return null;
Build & Test
cd functions && npm install # Install deps
cd functions && npm run build # Compile TypeScript
cd functions && npm test # Run Jest tests
Comments
Markdown supported