System Requirements:
Getting Started
//Loading Firebase Package
var firebase = require("firebase");
/**
* Update your Firebase Project
* Credentials and Firebase Database
* URL
*/
firebase.initializeApp({
serviceAccount: "<path to Firebase Credentials Json File>",
databaseURL: "<Firebase Database URL>"
}); //by adding your credentials, you get authorized to read and write from the database
/**
* Loading Firebase Database and refering
* to user_data Object from the Database
*/
var db = firebase.database();
var ref = db.ref("/user_data"); //Set the current directory you are working in
/**
* Setting Data Object Value
*/
ref.set([
{
id:20,
name:"Jane Doe",
email:"[email protected]",
website:"https://jane.foo.bar"
},
{
id:21,
name:"John doe",
email:"[email protected]",
website:"https://foo.bar"
}
]);
/**
* Pushing New Value
* in the Database Object
*/
ref.push({
id:22,
name:"Jane Doe",
email:"[email protected]",
website:"https://jane.foo.bar"
});
/**
* Reading Value from
* Firebase Data Object
*/
ref.once("value", function(snapshot) {
var data = snapshot.val(); //Data is in JSON format.
console.log(data);
});
npm install firebase
node index.js
What does the project actually do?
The project loads the Data from cloud based Firebase Database. The project also demonstrates how to Write and Read data from a Firebase Data Object.
In order to view your data get updated in realtime, go to your console click on the project you made, and on the left, hit Database. There, you can see your data get updated in real-time, along with their values.