Skip to content

Instantly share code, notes, and snippets.

@jiankaiwang
Created December 6, 2017 06:47
Show Gist options
  • Save jiankaiwang/dd744f2af3ea7285ca5f02f330429d06 to your computer and use it in GitHub Desktop.
Save jiankaiwang/dd744f2af3ea7285ca5f02f330429d06 to your computer and use it in GitHub Desktop.
It's the firebase API template in Nodejs server side, and also continuous fetching iot sensor data from the firebase.
/*
* author : jiankaiwang
* platform : nodejs
* feature : the firebase API template in NodeJS server side
* description : continuously fetch iot sensor data from the firebase
* reference : push data into firebase (https://gist.github.com/jiankaiwang/635f40bb5609033e922337b7aa2a44e6)
*/
var firebase = require("firebase");
// firebase configuration
var config = {
apiKey : "",
authDomain : "",
databaseURL : "https://xxx.firebaseio.com/"
storageBucket : ""
}
firebase.initializeApp(config);
var db = firebase.database();
// Get the key list of the dictionary.
var getDictionaryKeyList = function(getDictObj) {
var keyList = [];
for(var key in getDictObj) {
keyList.push(key);
}
return keyList;
}
// Get the value from the firebase.
var ref = db.ref("/cluster1/dev1");
ref.once("value", function(data) {
// output format is json-encoded
console.log(data.val());
// example to get the whole key
console.log(getDictionaryKeyList(data.val()));
// end nodejs application
process.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment