npm Firebase

Firebase is a product of Google that helps developers to build, manage, and grow their apps easily. It helps developers to build their apps faster and more securely. No programming is required on the Firebase side which makes it easy to use its features more efficiently. It provides services to Android, iOS, web, and Unity. It provides cloud storage. It uses NoSQL for the database to store data.

Steps to setup Firebase in Node JS Project

Create a Node Project

Initially set up a Nodejs Project using the following command.

npm init 
OR
npm init -y
  • The npm init command asks some setup questions that are important for the project
  • npm init -y command is used to set all the answers to the setup questions as yes.

Firebase Installation

You can install the package with npm using the following command:

npm install firebase
or
npm i firebase

We can check the version of the firebase through the package.json file.

Create a Firebase Project

  • Go to Firebase Console: Navigate to the Firebase Console.
  • Add a New Project: Click on “Add project” enter your project name, configure Google Analytics (optional), and click “Create Project.”

Register Your Web App

  • Add Firebase to Your Web App: In the Firebase console, click on the Web icon (</>) to register your web app.
  • Enter a Name: Give your app a nickname and click “Register app.”
  • Firebase SDK Setup: Firebase will provide a code snippet to add to your project. This snippet includes our project’s configuration.
import { initializeApp } from "firebase/app";

// Your web app's Firebase configuration

const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
  • Initially initializeApp function is imported from the firebase/app module which is used to initialize the app.
  • firebaseConfig object contains different keys which are associated the with the services provided firebase like Cloud Firestore , Authentication , Cloud Messaging.

Features of Firebase

  • Easily Integration with Third-Party Services.
  • Provide a powerful mechanism for maintaining the integrity and cleanliness of our Realtime Database.
  • It offers a scalable and cost-effective solution for executing computationally intensive tasks in the cloud.

Services by Firebase

Realtime Database

The Firebase Realtime Database is a cloud-based NoSQL database that manages your data at the blazing speed of milliseconds. In simplest term, it can be considered as a big JSON file.

The cloud Firestore is a NoSQL document database that provides services like store, sync, and query through the application on a global scale. It stores data in the form of objects also known as Documents. It has a key-value pair and can store all kinds of data like, strings, binary data, and even JSON trees.

Authentication

Firebase Authentication service provides easy to use UI libraries and SDKs to authenticate users to your app. It reduces the manpower and effort required to develop and maintain the user authentication service

Remote Config

The remote configuration service helps in publishing updates to the user immediately. The changes can range from changing components of the UI to changing the behavior of the applications. These are often used while publishing seasonal offers and contents to the application that has a limited life.

Hosting

Firebase provides hosting of applications with speed and security. It can be used to host Static or Dynamic websites and microservices. It has the capability of hosting an application with a single command

The FCM service provides a connection between the server and the application end users, which can be used to receive and send messages and notifications.