-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'use strict';
var firebase = require('firebase-admin');
var serviceAccount = "./serviceAccountKey.json"
firebase.initializeApp({
credential: firebase.credential.cert(serviceAccount),
databaseURL: 'https://nacho-crumbs.firebaseio.com'
});
//var ref = firebase.database().ref('subjects');
var ref = firebase.database().ref('ziv');
/*var subjectsRef = ref.child('subjects');
var subjectRef = subjectsRef.push({a:'a'});
var subjectKey = subjectRef.key;
var trans = {};
var subject = {
'title': 'Blood'
};
trans['subjects1/' + subjectKey] = subject;
trans['log/' + subjectKey] = subject;
ref.update(trans);
*/
//var messagesRef = ref.child('messages');
/*messagesRef.push({
name: 'ziv',
admin: true,
count: 1,
text: "hey ziv"
});*/
// ref.root.once('value')......
/*ref.child('log').parent.child('subjects').once('value').then(function(snap) {
console.log(snap.key + "\n");
console.log(snap.ref.toString() + "\n");
console.log(JSON.stringify(snap.val()) + "\n\n");
});
*/
//ref.child('log').on('value', function(snap) {
// console.log(JSON.stringify(snap.val()) + "\n\n");
//});
ref.child('log').orderByKey().limitToLast(1).on('child_added', function(snap) {
console.log(snap.val() + "\n\n");
});