framework icon indicating copy to clipboard operation
framework copied to clipboard

Is totaljs work with firebase ?

Open lyquocnam opened this issue 9 years ago • 1 comments

Hi author, Is totaljs work with firebase ? have any example ?

lyquocnam avatar Apr 01 '17 14:04 lyquocnam

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) {
		//.........
	});
});

molda avatar Apr 01 '17 17:04 molda