Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Firebase admin - how to initialise multiple applications in nodejs.

Firebase Admin Multi App Initialization - ES5

This is a snippet that uses firebase's firebase-admin to initialize multiple firebase projects in one admin application.

ES6 version

Using Javascript

require('firebase');
var admin = require('firebase-admin');
var firstServiceAccount = require('path/to/service-account-1');
var secondServiceAccount = require('path/to/service-account-2');

var _first = admin.initializeApp(
  {
    credential: admin.credential.cert(firstServiceAccount),
    databaseURL: 'https://<1st-db-name>.firebaseio.com'
  }, 
  'first' // this name will be used to retrieve firebase instance. E.g. first.database();
);

var _second = admin.initializeApp(
  {
    credential: admin.credential.cert(secondServiceAccount),
    databaseURL: 'https://<2nd-db-name>.firebaseio.com'
  }, 
  'second' // this name will be used to retrieve firebase instance. E.g. second.database();
);

exports.first = _first;
exports.second = _second;

Usage

var first = require('../path/to/the/file/above');
var second = require('../path/to/the/file/above');
 
first.database();
second.database();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.