Firebase playground

by borisjavier

HTML

<script src="//cdn.firebase.com/js/client/2.2.1/firebase.js"></script>
<a id='add'>add user</a>
<div id='data'>
data here
</div>

JavaScript

// Initialize Firebase
  var config = {
    apiKey: "AIzaSyBlRSwFdFKi_8voHc55w402xTkjWcqmSZo",
    authDomain: "test-93727.firebaseapp.com",
    databaseURL: "https://test-93727.firebaseio.com",
    storageBucket: "test-93727.appspot.com",
    messagingSenderId: "398327954343"
  };
  firebase.initializeApp(config);
  
  // Get a reference to the database service
  var database = firebase.database();
  
	$('a').click( function(e) {e.preventDefault(); 
      firebase.database().ref('users/' + (new Date()).toString()).set({
		    username: 'Alberto',
    		email: '[email protected]'
  		});
  return false; } );
  

  
 var updatedVals = firebase.database().ref('users/');
	updatedVals.on('value', function(snapshot) {
  	console.log('updated values',  snapshot.val())
    $('#data').append(JSON.stringify(snapshot.val()))
});