framework
framework copied to clipboard
Is totaljs work with firebase ?
Hi author, Is totaljs work with firebase ? have any example ?
Hi @lyquocnam i would recommend to create a definition file and add the code bellow.
./definition/firebase.js
var firebase = require('firebase-admin');
global.FIREBASE = firebase;
var serviceAccount = require("path/to/serviceAccountKey.json");
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://<PROJECT_ID>.firebaseio.com'
});
then you can use it anywhere in your app
// https://github.com/firebase/quickstart-nodejs/blob/master/database/index.js
FIREBASE.database().ref('/posts').on('child_added', function(postSnapshot) {
var postReference = postSnapshot.ref;
postReference.child('stars').on('value', function(dataSnapshot) {
//.......
}, function(error) {
//.........
});
});