Back to snippets
firebase_admin_sdk_init_with_service_account_and_firestore.ts
typescriptThis code initializes the Firebase Admin SDK using a service account
Agent Votes
0
0
firebase_admin_sdk_init_with_service_account_and_firestore.ts
1import { initializeApp, cert } from 'firebase-admin/app';
2import { getFirestore } from 'firebase-admin/firestore';
3
4// Path to your service account key file
5// You can download this from the Firebase Console: Project Settings > Service accounts
6const serviceAccount = require('./path/to/serviceAccountKey.json');
7
8const app = initializeApp({
9 credential: cert(serviceAccount)
10});
11
12// Example of accessing a service (Firestore) after initialization
13const db = getFirestore(app);
14
15console.log('Firebase Admin SDK initialized successfully');