Check Out the Stream @https://twitch.tv/talk2megooseman
Today Objective
✅ Work on a fork of
talk2MeGooseman / firestore-backup-restore
NPM package for backup and restore Firebase Firestore
firestore-export-import
NPM package for backup and restore Firebase Firestore
You can export and import data from firestore with sub collection.
Installation
Install usingnpm.
npm install firestore-export-import
Get Google Cloud Account Credentials from Firebase
You canGenerate New Private Key from Project Settings fromFirebase Console.
After that you need to copy thedatabaseURL for initiating the App.
Usage
You have to import this package in a JavaScript file and work from there.
Export data from firestore
You can export collection and sub collection from your data. The sub collection is optional.
// In your index.jsconstfirestoreService=require('firestore-export-import')constserviceAccount=require('./serviceAccountKey.json')// Initiate Firebase AppfirestoreService.initializeApp(serviceAccount, databaseURL)// Start exporting your datafirestoreService .backup('collection-name','sub-collection-optional') .then(data=>console.log…
npx
support to itNotes
NPX
During off stream time I was looking for a good way to export Firestore data that I have for a couple of my extension s so that I can import into any other DB service of my choice.
Unfortunately Firebase does not offer a clean export tool, instead, you can only export to their propriety format. BUT I ended finding an NPM package that someone wrote to export data to JSON:firestore-export-import
I was lazy and didn't want to spend time integrating this package into any project I have. So instead I got the crazy idea, "What if I made this npx compatible?" And here we are now.
So I forked the repo and start laying the groundwork for creatingnpx
compatible version of this package.
I got alot of my inspiration of how to do this from the cowsay package:
cowsay
__________________< srsly dude, why? > ------------------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
cowsay is a configurable talking cow, originally written in Perl byTony Monroe
This project is a translation in JavaScript of the original program and an attempt to bring the same silliness to node.js.
Install
npm install -g cowsay
Usage
cowsay JavaScript FTW
or
cowthink node.js is cool
It acts in the same way as the original cowsay, so consultcowsay(1)
or runcowsay -h
________< indeed > -------- \ \ .::!!!!!!!:. .!!!!!:. .:!!!!!!!!!!!! ~~~~!!!!!!. .:!!!!!!!!!UWWW$$$ :$$NWX!!: .:!!!!!!XUWW$$$$$$$$$P $$$$$##WX!: .<!!!!UW$$$$" $$$$$$$$# $$$$$ $$$UX :!!UW$$$$$$$$$ 4$$$$$* ^$$$B $$$$\ $$$$$$$$$$$$ d$$R" "*$bd$$$$ '*$$$$$$$$$$$o+#" """" """""""
Usage as a module
cowsay can be used as any other npm dependency
var cowsay = require("cowsay");console.log(cowsay.say({ text : "I'm a moooodule", e : "oO", T : "U "}));// or cowsay.think()
_________________( I'm a
…After completing the work and getting the MVP done for import and export, next came refactor phase. One thing that I realized needed a refactoring was the usage ofoptimist
It has been deprecated for a long time so I wanted to look for a better alternative. Luckily ABuffSeagull came flying in and recommendedcommander
The end result is the it worked out great and I feel like the command and options structure feels a lot better.
Shoutouts and Thanks
ABuffSeagull
- Thanks for recommending commander.js and an alternative to optimist cli packagecommander
Kodder
- 2 month resub!
Booperinos
- Thanks for the 18 months of sub love!
Future action items
⬜ Wrap up doing a pull request for firestore-backup-restore. But its a done MVP <3
talk2MeGooseman / firestore-backup-restore
NPM package for backup and restore Firebase Firestore
firestore-export-import
NPM package for backup and restore Firebase Firestore
You can export and import data from firestore with sub collection.
Installation
Install usingnpm.
npm install firestore-export-import
Get Google Cloud Account Credentials from Firebase
You canGenerate New Private Key from Project Settings fromFirebase Console.
After that you need to copy thedatabaseURL for initiating the App.
Usage
You have to import this package in a JavaScript file and work from there.
Export data from firestore
You can export collection and sub collection from your data. The sub collection is optional.
// In your index.jsconstfirestoreService=require('firestore-export-import')constserviceAccount=require('./serviceAccountKey.json')// Initiate Firebase AppfirestoreService.initializeApp(serviceAccount, databaseURL)// Start exporting your datafirestoreService .backup('collection-name','sub-collection-optional') .then(data=>console.log…
Top comments(5)

- LocationEarth, Milky Way
- WorkSenior Performance Engineer at platformOS
- Joined
I wish we used yargs instead of commander for our company cli tool. It has been problematic over the years and it seems like it wants to do too much making it harder to introduce new devs into the project.

- LocationSan Diego
- WorkFull Stack Engineer at Coding Zeal
- Joined
Oh interesting! I am still new to libraries to use to make a good CLI interface. What would you say are the best reason to use yargs? Ill take a look at it since I am making another npx script for another project. Thanks for commenting and suggesting it.

- LocationEarth, Milky Way
- WorkSenior Performance Engineer at platformOS
- Joined
The best reason to use yargs for me is that i had a lot of issues with commander and a lot of serious tools are written using yargs. It also looks lighter/simpler/more focused on args parsing, which is nice.

- LocationSan Diego
- WorkFull Stack Engineer at Coding Zeal
- Joined
Thanks a lot for the suggestion, Ill be switching to yargs on a new npx project since I like the offerings over commander.

- LocationSan Diego
- WorkFull Stack Engineer at Coding Zeal
- Joined
Took a quick look at yargs and HOT DAMN it looks good. Importing a directory full of command modules? Yes, please. Thanks for telling me about this.
For further actions, you may consider blocking this person and/orreporting abuse