-
-
Save arnav-kr/8df69237d25d941e60115bfcf489ab00 to your computer and use it in GitHub Desktop.
Firebase Admin SDK Starter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FIREBASE_SERVICE_ACCOUNT_JSON={"type": "service_account","project_id": "###############","private_key_id": "################################","private_key": "-----BEGIN PRIVATE KEY-----\n##########################-----END PRIVATE KEY-----\n","client_email": "##########################","client_id": "#########################","auth_uri": "##################################","token_uri": "################################","auth_provider_x509_cert_url": "#####################","client_x509_cert_url": "###############"} | |
| FIREBASE_REALTIME_DATABASE_URL=************************ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add admin SDK | |
| require("dotenv").config(); | |
| const admin = require('firebase-admin'); | |
| // Get the Service Account JSON form environment variable and convert to object | |
| // to get the Service Account JSON file Open your project settings go to "Service Account" section | |
| // and click on "generate new key" to get the file. | |
| const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT_JSON); | |
| // Initialize the SDK | |
| admin.initializeApp({ | |
| // Takes the credentials | |
| credential: admin.credential.cert(serviceAccount), | |
| // Database URL of realtime database (Required only if you are using realtime database) | |
| databaseURL: process.env.FIREBASE_REALTIME_DATABASE_URL | |
| }); | |
| //initialization done Admin SDK ready to use! | |
| // now get the firebase services to use it | |
| const db = admin.firestore(); | |
| const rtdb = admin.database(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment