Fastify v5+ plugin for firebase-admin. Full TypeScript support.
- Works with service account JSON or Application Default Credentials (GCP)
- Supports
databaseURL,storageBucket, and custom appname - Accepts both camelCase and snake_case cert keys
- Singleton Firebase app with auto-cleanup on close
- Zero config on Cloud Run / Cloud Functions
npm i fastify-firebaseimport Fastify from 'fastify';
import fastifyFirebase from 'fastify-firebase';
import cert from './firebase.json';
const app = Fastify();
app.register(fastifyFirebase, cert);
app.get('/users', async (req, reply) => {
const snapshot = await req.server.firebase.firestore().collection('Users').get();
reply.send(snapshot.docs.map((doc) => doc.data()));
});
app.listen({port: 3000});app.register(fastifyFirebase); // uses Application Default Credentialsapp.register(fastifyFirebase, {
...cert,
name: 'my-app', // custom app name (default: 'default')
databaseURL: 'https://my-app.firebaseio.com', // for Realtime Database
storageBucket: 'my-app.appspot.com', // for Cloud Storage
});| Option | Type | Description |
|---|---|---|
projectId / project_id |
string |
Firebase project ID |
privateKey / private_key |
string |
Service account private key |
clientEmail / client_email |
string |
Service account email |
name |
string |
Firebase app name (default: 'default') |
databaseURL |
string |
Realtime Database URL |
storageBucket |
string |
Cloud Storage bucket |
All options are optional when using Application Default Credentials on GCP. When providing a cert, all three cert fields are required.
- BREAKING: Registering without options no longer throws uses Application Default Credentials instead
- New options:
databaseURL,storageBucket - Firebase app is now deleted on Fastify close (auto-cleanup)
- Error messages are more specific
- Requires Fastify v5+
- ESM-only (
import/export) - Plugin is async/Promise-based