Firebase

Perks of Firebase

  • Fast Data Synchronization
  • No backend server to worry about
  • Built-in Authentication
  • Free-hosting*
  • Instant Scalability 

Save Data to the cloud

Since Firebase itself is a No SQL database you easily store data as simple JSON documents

{
  "users": {
    "mchen": {
      "friends": { "brinchen": true },
      "name": "Mary Chen",
      // our child node appears in the existing JSON tree
      "widgets": { "one": true, "three": true }
    },
    "brinchen": { ... },
    "hmadi": { ... }
  }
}

Realtime Data

  • Firebase is simply a database with RESTful API
  • However, not just an API
  • Updates every client with the newest information
  • Huge Selling Point

User Authentication

Hosting

Instant Scalability

Basics of Data

Creating a Firebase Reference

  • Before reading and writing data we need to creat a reference to it. This data is loaded with a specified URL
var ref = new Firebase('https://youKaraoke.firebaseio.com/');
  • You can also reference different paths
var roomRef = new Firebase("https://youKaraoke.firebaseio.com/room");

Saving Data

Standard ways to save 

  • .set()
  • .push()
  • .update()

Best Practices

  • Avoid Nesting
{
"rooms": {
    "one": {
        "name": "room alpha",
        "type": "private",
        "messages": {
    "m1": { "sender": "mchen", "message": "foo" },
    "m2": { ... },
            }
        }
    }
}

Retrieving Data

Listeners

  • Data is retrieved by attaching an asynchronous listener to a Firebase reference.
  • The listener will be triggered once for the initial state of the data and again anytime the data changes
ref.on("value", function(dataSnapshot) {
    console.log(dataSnapshot.val());
});

Read event Types

  • value
  • child added
  • child changed
  • child removed

Awesome FrameWorks

  • AngularFire
  • EmberFire
  • ReactFire
  • BackboneFire

$firebase service

  • The primary purpose of $firebase is to manage synchronized data
  • These are some of the methods it contains 
  1. $asObject()
  2. $asArray()
  • Three-way Data Binding

Hosting

Quick and Easy

  • Just three steps 
$ npm install -g firebase-tools
$ firebase init
$ firebase deploy
  • Gets deployed to 
your-firebase-name.firebaseapp.com

Go try firebase

Firebase

By es1831

Firebase

  • 1,624