Firebase Realtime Database CRUD

Notes to create, read, update, delete an entry from Firebase realtime database.

index.html

<script src="https://unpkg.com/firebase/firebase.js"></script>

main.js

firebase.initializeApp({
apiKey: "[api_key]",
authDomain: "[any_title].firebaseapp.com",
databaseURL: "https://[any_title].firebaseio.com",
storageBucket: "[any_title].appspot.com",
});
var messagesRef = firebase.database().ref('messages');

Create

messagesRef.push(message).then(...);

Read

messagesRef.child(messageId).once('value').then(snapshot => {
...
});

Update

messagesRef.child(message['.key']).set(message).then(...);

Delete

messagesRef.child(message['.key']).remove();
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.