TypeScript icon, indicating that this package has built-in type declarations

0.5.0 • Public • Published


NPM Version Test CI Status Coverage Status

🔌 A Firestore database connector for

This package provides a database connector that allows you to use a Firebase Cloud Firestore instance to store metadata and game state.


npm install --save bgio-firebase


This example shows one way to use the database connector when running your server on most Google infrastructure. For more details on configuring Firebase on your server, see the Firebase documentation.

const admin = require('firebase-admin');
const { Server } = require('');
const { Firestore } = require('bgio-firebase');
const { MyGame } = require('./game');

const database = new Firestore({
  config: {
    credential: admin.credential.applicationDefault(),
    databaseURL: 'https://<MY-PROJECT>',

const server = Server({
  games: [MyGame],
  db: database,


The Firestore class can be configured with an options object with the following properties.


  • type: string

If you are using multiple Firebase apps on your server, pass in the name of the app the Firestore connector should use.


  • type: admin.AppOptions

An options object to pass to the Firebase Admin SDK's initializeApp method. This configures your connection with Firebase. See the Firebase docs for details.


  • type: string
  • default: 'bgio_'

Prefix for the collections within your Firebase project.


  • type: boolean
  • default: true

By default, the Firestore instance’s settings method is called internally to avoid errors from undefined values in data from settings can only be called once, so if you want to call it with your own custom options, you can pass false here to disable the internal call.


  • type: boolean
  • default: false

This connector tries to be as efficient as possible with minimal set-up, but due to Firestore’s query limitations, it cannot combine a date range query with other queries when listing matches without a composite index. By default, it will fall back to less efficient server-side filtering in these cases, potentially resulting in more database reads than necessary. You may wish to enable composite indexes if you use the Lobby API’s updatedAfter or updatedBefore queries when listing matches. See the Firestore docs for details on managing indexes.

Database structure

collection ID document ID contents
{dbPrefix}metadata {matchID} match metadata
{dbPrefix}state {matchID} game state
{dbPrefix}initialState {matchID} initial game state
{dbPrefix}log {matchID} game action logs


Bug reports and pull requests are very welcome! I’m not a database expert or a Firebase expert or any kind of expert, so it’s very possible that there could be improvements to how the connector interfaces with Firebase. If you run into any problems or have questions, please open an issue.

Please also note the code of conduct and be kind to each other.


The code in this repository is provided under the MIT License.


DownloadsWeekly Downloads






Unpacked Size

26.1 kB

Total Files


Last publish


  • nicolodavis
  • jasonharrison
  • flamecoals
  • delucis