Getting Started with Firebase
BIM

Getting Started with Firebase

Hikari

Introduction

I am using Firebase in my project and I have to admit that this is really a powerful tool for building a system with powerful data processing support features. .Firebase is a powerful Backend-as-a-Service (BaaS) platform by Google that simplifies web and mobile app development. It provides a suite of tools for authentication, real-time database, hosting, cloud functions, and more. Whether you're building a small personal project or a large-scale application, Firebase can help streamline development and improve scalability. In this tutorial, we'll go over the basics of Firebase and how to set up a simple project.


I will introduce how to set up Firebase into a project:

Step 1: Setting Up Firebase

To start using Firebase, follow these steps:

1.Create a Firebase Project

  • Visit Firebase Console and sign in with your Google account.
  • Click “Create a Project” and follow the setup instructions.

2.Add Firebase to Your App

  • Select the platform (Web, Android, iOS).
  • Follow the instructions to integrate Firebase SDK.

3.Install Firebase in Your Project (For web applications)

Install by Bash:

npm install firebase

Then , import Firebase into your JavaScript project:

import { initializeApp } from "firebase/app";

const firebaseConfig = {
    apiKey: "YOUR_API_KEY",
    authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
    projectId: "YOUR_PROJECT_ID",
};

const app = initializeApp(firebaseConfig);

4.Access Firebase in your app

Firebase services (like Cloud Firestore, Authentication, Realtime Database, Remote Config, and more) are available to import within individual sub-packages.

The example below shows how you could use the Cloud Firestore Lite SDK to retrieve a list of data.

import { initializeApp } from 'firebase/app';
import { getFirestore, collection, getDocs } from 'firebase/firestore/lite';
// Follow this pattern to import other Firebase services
// import { } from 'firebase/<service>';

// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
  //...
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

// Get a list of cities from your database
async function getCities(db) {
  const citiesCol = collection(db, 'cities');
  const citySnapshot = await getDocs(citiesCol);
  const cityList = citySnapshot.docs.map(doc => doc.data());
  return cityList;
}

Conclusion

Firebase simplifies backend development by providing a comprehensive suite of tools, enabling developers to focus on building great applications. Whether you're developing a small hobby project or a full-scale application, Firebase offers scalability and flexibility.

Have you tried Firebase yet? Let me know if you need help with any specific feature!