Created
April 17, 2017 20:02
-
-
Save UlisesGascon/be77e9ff16259c393e2aa8794426da88 to your computer and use it in GitHub Desktop.
Backaup as JSON file any public data available in a Firebase Database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
---- 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