Skip to content

Instantly share code, notes, and snippets.

@UlisesGascon
Created April 17, 2017 20:02
Show Gist options
  • Save UlisesGascon/be77e9ff16259c393e2aa8794426da88 to your computer and use it in GitHub Desktop.
Save UlisesGascon/be77e9ff16259c393e2aa8794426da88 to your computer and use it in GitHub Desktop.
Backaup as JSON file any public data available in a Firebase Database
/*
---- In terminal ----
1. npm install [email protected]
2. node firebase_backup database_url
example: node firebase_backup https://docs-examples.firebaseio.com/
*/
var fs = require('fs');
var Firebase = require("firebase")
var ref = new Firebase(process.argv[2]);
ref.once("value", function(snapshot) {
fs.writeFile("data.json", JSON.stringify(snapshot.val()), function(err) {
if(err) {
return console.log(err);
} else {
console.log("The file was saved!");
}
process.exit()
});
console.log("Saving Data");
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
process.exit()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment