Firebase Cheat Sheet

Here’s a cheat sheet for Firebase, a popular mobile and web application development platform:

Firebase Basics

Initialize Firebase:

firebase init

Deploy Firebase Project:

firebase deploy

Firebase Authentication

Sign Up a User:

firebase.auth().createUserWithEmailAndPassword(email, password)

Sign In a User:

firebase.auth().signInWithEmailAndPassword(email, password)

Sign Out:

firebase.auth().signOut()

Firestore Database

Add Data:

firebase.firestore().collection('collectionName').add(data)

Read Data:

firebase.firestore().collection('collectionName').get()

Update Data:

firebase.firestore().collection('collectionName').doc('documentId').update(data)

Delete Data:

firebase.firestore().collection('collectionName').doc('documentId').delete()

Realtime Database

Read Data:

firebase.database().ref('path').once('value')

Write Data:

firebase.database().ref('path').set(data)

Cloud Functions

Deploy Cloud Functions:

firebase deploy --only functions

Hosting

Deploy Hosting:

firebase deploy --only hosting

Cloud Storage

Upload File to Storage:

const storageRef = firebase.storage().ref();
const fileRef = storageRef.child('path/to/file');
fileRef.put(file);

Download File from Storage:

const fileUrl = await storageRef.child('path/to/file').getDownloadURL();

Firebase CLI

List Available Commands:

firebase help

Emulate Functions Locally:

firebase emulators:start --only functions

Deploy Specific Function:

firebase deploy --only functions:functionName

Firebase Hosting Rewrite

Configure Hosting Rewrite: Edit firebase.json:

"rewrites": [
  {
    "source": "**",
    "destination": "/index.html"
  }
]

Firebase Analytics

Initialize Analytics:

firebase.analytics();

This cheat sheet covers some essential Firebase commands and functionalities. Customize it based on your specific needs and Firebase features you are using in your project.