npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fortune-firestore

v0.3.0

Published

Firestore adapter for Fortune.

Readme

Fortune Firestore Adapter

Build Status npm Version License XO code style

This is a Firestore adapter for Fortune. It uses Google’s official Node.js client for Google Cloud Firestore.

It is ported from fortunejs/mongodb and incoporates some design ideas from the third-party Google Cloud Datastore adapter.

Usage

Install the fortune-firestore package with yarn or npm:

$ yarn add fortune-firestore
$ npm install fortune-firestore

Then use it with Fortune:

import fortune from "fortune";
import firestoreAdapter from "fortune-firestore";

const store = fortune({ ... }, {
  adapter: [
    firestoreAdapter,
    { // options
      projectId: "my firebase/google cloud project id",
      keyFilename: "path/to/some/keyFile.json",
      credentials: {
        client_email:
        "[email protected]",
        private_key: "some long private key"
      }
    }
  ]
});

Connecting to Firestore

For the adapter to connect to Firestore, as it’s implemented, one of the following three combinations of options must be present, as above:

  1. keyFilename as a JSON file.
  2. projectId, credentials.client_email, and credentials.private_key, as likely harvested from the keyFile.
  3. keyFilename as .pem or .p12 file, projectId, and credentials.client_email

Getting a keyFile

Both Firebase and Google Cloud Platform use the GCP interface to manage service accounts, so you should log in to the GCP console.

  1. Select the appropriate project for the adapter.
  2. Navigate to “IAM & Admin” and then “Service accounts.”
  3. Click on an appropriate service account or create a new one. If you create a new one, it should have the “Cloud Datastore User” role at a minimum.
  4. Generate a key by clicking on “+ Create Key.” This will give you the option of downloading a JSON keyFile or a .p12 keyFile.

This keyFile, by itself, is sufficient to connect to Firestore. However, seeing as you should never commit this file, it may make more sense to harvest a few keys from it and use them as environment variables. The properties to harvest into your environment are project_id, private_key, and client_email.

Note that private_key is likely to have special characters that may break with some continuous integration solutions like Travis. My solution in spec/helpers.js is to encode the private key as a hex string, paste that blob into Travis, and then convert that back to ascii within the script.

Options

In addition to the credentials indicated above, the adapter anticipates four options:

  • typeMap: An object that maps type names (keys) to collection names (values). For example: {user: "users"}. If unset, it assumes the type passed from Fortune has the same name as the collection in Firestore.
  • bufferEncoding: Fortune provides for saving Buffer-type blobs in records. Firestore does not, without using their custom Blob type. Instead, the adapter converts all fields indicated as type: Buffer in the record types to strings. This option sets the encoding for that conversion. The default is "base64".
  • convertTimestamps: Firestore receives Dates and converts them to Timestamps. By default, this option is set to true, meaning that when records are fetched, the adapter converts the Timestamps Firestore has saved to Dates.
  • nullUndefinedFields: Firestore doesn’t know about the schema you have registered with Fortune. It will make a record with as many fields as are passed in the create() method. Fortune, however, expects undefined fields to be set as null or [] (if they are arrays). This parameter, which defaults to true can be deactivated, keeping the skinny records.

Contributing, etc.

Please do. I ported this by writing to the tests that Fortune provides, but I have not yet tested the adapter in the wild.

License

This software is licensed under the MIT License.