Last active
April 5, 2017 16:56
-
-
Save bwsewell/05fd8dd77f39c99650c24d8630040b52 to your computer and use it in GitHub Desktop.
Intro to Firebase Realtime Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = { | |
apiKey: "<API_KEY>", | |
authDomain: "<PROJECT_ID>.firebaseapp.com", | |
databaseURL: "https://<DATABASE_NAME>.firebaseio.com", | |
}; | |
firebase.initializeApp(config); | |
var database = firebase.database(); | |
var notesRef = database.ref('notes'); | |
var textarea = document.getElementById('notes'); | |
// Save the contents of the textarea to firebase | |
textarea.addEventListener('keyup', function() { | |
notesRef.set(textarea.value); | |
}); | |
// Set of textarea to what we have in firebase any time | |
// the data on firebase changes (this includes on page load) | |
notesRef.on('value', function(snapshot) { | |
textarea.value = snapshot.val(); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://www.gstatic.com/firebasejs/3.7.4/firebase.js"></script> | |
</head> | |
<body> | |
<h1>Notes</h1> | |
<textarea id="notes" cols="100" rows="10"></textarea> | |
</body> | |
<script src="app.js"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment