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

@kdrowe/firestore-json

v1.0.2

Published

Super simple importing and exporting of JSON data to and from Firebase (Firestore).

Downloads

13

Readme

firestore-json

Super simple importing and exporting of JSON data to and from Firebase (Firestore).

Doubles as either a command-line tool or a resuable node.js package/library for use in your own applications.

Example JSON File

{
  "books": {
    "$type": "collection",
    "book42": {
      "title": "The Life and Times of a Software Engineer",
      "author": "Cody Bytes",
      "genre": "Non-fiction",
      "reviews": {
        "$type": "collection",
        "review1": {
          "author": "I.M. Reading",
          "rating": 5,
          "comment": "A thrilling saga of coffee, code, and bugs. A must-read for anyone who's ever wondered why their program works on the second run."
        }
      }
    },
    "book007": {
      "title": "Debugging: The Hard Way",
      "author": "Try N. Catch",
      "genre": "Horror",
      "reviews": {
        "$type": "collection",
        "review2": {
          "author": "Anne Algorithm",
          "rating": 4,
          "comment": "Frighteningly accurate depiction of a programmer's descent into madness. I couldn't put it down, mostly because I was afraid it would crash if I did."
        }
      }
    }
  }
}

Prerequisites

  • Node.js installed on your machine

Use without cloning this repo locally

Below are example commmands that can be run from anywhere that node.js is installed to import and export data to/from Firestore.

Command-line parameters explained:

  • --project specifies the GCP project ID
  • --service-account-key specifies the local file name, or path and file name, for the json key file of a service account in the GCP project that has access to the Firestore database

Import

npx @kdrowe/firestore-json import -- my-data.json --project=$PROJECT_ID --service-account-key=key.json

Export

npx @kdrowe/firestore-json export -- my-data.json --project=$PROJECT_ID --service-account-key=key.json

Installed Usage

Install Locally

Clone this repo, then run the following command:

npm install

Importing Data

To import data from a JSON file into your Firestore datbase, use the following command:

npm start import -- [file-name.json] --project=[my-gcp-project-id] --service-account-key=key.json

Replace [file-name.json] with the path to your JSON file and [my-gcp-project-id] with your actual GCP project ID.

Exporting Data

To export data to a JSON file from your Firestore database, use the following command:

npm start import -- [file-name.json] --project=[my-gcp-project-id] --service-account-key=key.json

Replace [file-name.json] with the desired outfile file path/name and [my-gcp-project-id] with your actual GCP project ID.

Use it in Your Own Node.js Application

First, ensure you've installed firestore-json in your project:

npm install @kdrowe/firestore-json

Example: Importing JSON Data to Firestore

const firestoreJson = require('@kdrowe/firestore-json');

// Configuration for importing
const importConfig = {
  fileName: 'path/to/your/input.json', // Path to the JSON file you want to import
  projectId: 'your-gcp-project-id', // Your GCP Project ID
  serviceAccountKeyPath: 'path/to/your/serviceAccountKey.json' // Path to your Firebase service account key file
};

// Execute the import
firestoreJson.import.execute(importConfig)
  .then(() => console.log('Import successful'))
  .catch((error) => console.error('Import failed', error));

Example: Exporting Firestore Data to JSON

const firestoreJson = require('@kdrowe/firestore-json');

// Configuration for exporting
const exportConfig = {
  projectId: 'your-gcp-project-id', // Your GCP Project ID
  serviceAccountKeyPath: 'path/to/your/serviceAccountKey.json', // Path to your Firebase service account key file
  fileName: 'path/to/your/output.json' // Path where you want to save the exported JSON
};

// Execute the export
firestoreJson.export.execute(exportConfig)
  .then(() => console.log('Export successful'))
  .catch((error) => console.error('Export failed', error));