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 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-firestore

v1.2.7

Published

Simple module to easily interact with Firestore, with optional caching!

Downloads

10

Readme

Simple Firestore

simple-firestore is a simple module to easily interact with Firestore, with optional caching!

Features

  • Super easy-to-use
  • Optional caching with Redis
  • Very customizable
  • Perfect for Discord Bots

Requirements

Installation

npm install simple-firestore
yarn add simple-firestore

Getting Started

Example

const SimpleFirestore = require("simple-firestore")

async function example() {

    const db = await SimpleFirestore({
        credentials: {
            apiKey: "<YOUR_API_KEY>",
            authDomain: "<YOUR_AUTH_DOMAIN>",
            projectId: "<YOUR_PROJECT_ID>",
            storageBucket: "<YOUR_STORAGE_BUCKET>",
            messagingSenderId: "<YOUR_MESSAGING_SENDER_ID>",
            appId: "<YOUR_APP_ID>"
        },
        useCache: true, 
        cacheTTL: 60*2, // seconds
        cachePrefix: "bot",
        logs: true
    })
}

example()

What is that?

  • credentials: these are the values you copy from your Firebase App
  • useCache: enabling this option will use Redis to cache the data you're getting from Firebase, in order to avoid high amounts of reads on your database
  • cacheTTL: the amount of time the data stays stored in cache (in seconds), this can be helpful for ensuring we don't waste resources on data that is not accessed often.
  • cachePrefix: this is useful if you're running different projects in the same Redis server, and want each project to have their own cache prefix
  • logs: receive logs on your terminal

Methods

.set(path, field, value, customTTL?)

This function adds/updates data in your database

await db.set("users/12345", "test", { foo: "bar", simple: "example" })

Using Dot Notation

await db.set("users/12345", "test.foo", "bar")

await db.set("users/12345", "test.simple", "example")

Using Custom TTL (optional)

await db.set("users/12345", "test", { foo: "bar", simple: "example" }, 60*10)

.get(path, field)

This function returns data from your database

await db.get("users/12345", "test")
// -> { foo: "bar", simple: "example" }

Using Dot Notation

await db.get("users/12345", "test.foo")
// -> "bar"

await db.get("users/12345", "test.simple")
// -> "example"

.deleteField(path, field)

This function deletes a specific field from a document

await db.deleteField("users/12345", "test")

.deleteDoc(path)

This function deletes a specific document from a collection

await db.deleteDoc("users/12345")