node.jsfirebasefirebase-realtime-databasegoogle-cloud-functionsfirebase-admin

How to change admin.initializeApp when deploying different environments


I am using Firebase Functions. I have 2 environments: one for dev and other for staging.

My question is how can I change admin.initializeApp config when deploying to each environment because the databaseURL is changing:

admin.initializeApp({
  credential: [...],
  databaseURL: "someurl"
});

Thanks!


Solution

  • You do this just like you are using the Firebase Admin SDK in a regular node.js app. The setup instructions are here. There are also instructions in the Firebase console when you go to download the project's service account credentials.

    When you download the service account key file, you can put it in your functions directory so it can be loaded with require() and passed to initializeApp.