Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Node JS – Initialize Firebase using service account key or Firebase config file?

I’m trying to learn how to use Firebase with Node JS and there’s a thing I can’t understand. I’ve been looking for an explanation for a few days now, but I just can’t find something useful.

After following some tutorials, I’m confused because some of them use the serviceAccountKey file which looks like

    "type": "service_account",
    "project_id": 
    "private_key_id": 
    "private_key":
    "client_id": 
    "auth_uri": 
    "token_uri": 
    "auth_provider_x509_cert_url": 
    "client_x509_cert_url":

and then they initialize it like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

admin.initializeApp({
    credential: admin.credential.cert(credentials)
});

While others use the Firebase configuration file which is generated when you register the app on Firebase, which looks like this:

const firebaseConfig = {
  apiKey: 
  authDomain:
  projectId:
  storageBucket:
  messagingSenderId: 
  appId:
  measurementId:
}

What is the difference? When are you supposed to use the first way or the second way?
If there is some documentation about this, please help me with it because I can’t find anything relevant.

>Solution :

The first one you mentioned is for backend / Admin SDK code.

The second one is for the frontend / web SDK.

These SDKs are not compatible with each other and require different ways to initialize them.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading