Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save somersbmatthews/d35736fbbd6b23e5cfe8cf9b4c02ecba to your computer and use it in GitHub Desktop.
Save somersbmatthews/d35736fbbd6b23e5cfe8cf9b4c02ecba to your computer and use it in GitHub Desktop.
Firebase admin - how to initialise multiple applications in ES6 nodejs.

Firebase Admin Multi App Initialization - ES6

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

ES5 version

Using ES6

import 'firebase';
import * as admin from 'firebase-admin';
import firstServiceAccount from 'path/to/service-account-1';
import secondServiceAccount from '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();
);

export const first = _first;
export const second = _second;

Usage

import { first, second } from '../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