Skip to content

Instantly share code, notes, and snippets.

@izotx
Last active June 9, 2022 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izotx/061e96cc9f49c63fc4bc2c22edb79188 to your computer and use it in GitHub Desktop.
Save izotx/061e96cc9f49c63fc4bc2c22edb79188 to your computer and use it in GitHub Desktop.
var firebase = require("firebase");
var RSVP = require('rsvp');
exports.getInstance = function(){
initFirebase()
return firebase
}
/**Responsible for initalizing firebase database.*/
function initFirebase(){
var config = {
apiKey: "AIzaSyB1As1MtKDc7iNA5GEqf0W6f_k1bQNzJFE",
authDomain: "summerhousing-5c0cf.firebaseapp.com",
databaseURL: "https://summerhousing-5c0cf.firebaseio.com",
projectId: "summerhousing-5c0cf",
storageBucket: "summerhousing-5c0cf.appspot.com",
messagingSenderId: "493524743868"
};
firebase.initializeApp(config);
}
/**Helper for getting collections*/
exports.getCollection = function (collectionName){
var promise = new RSVP.Promise(function(fulfill, reject) {
firebase.database().ref(collectionName).on("value", function(snapshot) {
// console.log(snapshot);
let array = []
// let colleges = snapshot.val();
snapshot.forEach(function(snap){
var el = snap.val()
el.key = snap.key
array.push(el)
});
fulfill(array)
});
});
return promise
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment