Book Image

Firebase Cookbook

By : Houssem Yahiaoui
Book Image

Firebase Cookbook

By: Houssem Yahiaoui

Overview of this book

Do you feel tired just thinking or even hearing about backend technologies, authentication or the tedious task of deployment? Firebase is here to change the way you develop and make your app a first-class citizen of the cloud. This books takes a solution based approach by providing you recipes that would help you understand the features of Firebase and implement them in your existing web or mobile applications. We start-off by creating our first Firebase application and integrating its services into different platforms and environments for mobile as well as web applications. Then we deep dive into Real-time Database and Firebase Storage that allows your users to access data across various devices with realtive ease. With each chapter you will gradually create the building blocks of your application from securing your data with Firebase Rules to authenticating your users with O-Auth. Moving along we would explore modern application development techniques such as creating serverless applications with Firebase Cloud Functions or turning your traditional applications into progressive apps with Service workers. Finally you will learn how to create cross-platform mobile apps, integrate Firebase in native platforms, and learn how to monetize your mobile applications using Admob for Android and iOS.
Table of Contents (15 chapters)
Firebase Cloud FireStore

Integrating Firebase into the backend

Firebase is already a complete solution that can simply replace our backend, but sometimes, due to some requirements, you will find yourself integrating Firebase into the already present backend.

In this integration process, we will integrate Firebase services in a NodeJS backend application.

How to do it...

Since we're using NodeJS, integrating Firebase is one module setup away:

  1. Head directly to your terminal (cmd on Windows) and write down the following command:
     ~ cd project-directory
~/project-directory ~> npm install firebase --save

Now, the preceding command will go and download Firebase locally so you can access it directly using your normal commonJS workflow.

  1. Now, you will need to grab yourself a copy of your Firebase project configuration. This step is relatively easy as you can find the required configuration metadata by following the steps mentioned in the previous section, Adding Firebase to an existing frontend project, where we introduced how we can add Firebase to a frontend project.
  2. Head directly to your favorite code editor and write down the following:
      // [*] 1: requiring/importing Firebase in our 
const firebase = require('firebase');

// [*] 2:Initialising our application with our
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>",
storageBucket: "<BUCKET>",

Congratulations, you've successfully integrated Firebase within your backend workflow. I also want to point out that we can extend the workflow we have now using something called Firebase Admin SDK. We will cover how we integrate it and work with it in Chapter 7, Firebase Admin SDK.

How it works...

Similar to the frontend integration, in our backend we are doing the following:

  1. Using a node package manager or npm to install the Firebase commonJS library, where we will find all the necessary APIs.
  2. We're requiring/importing Firebase to be part our application, passing it to the configuration object that will hold all our API keys, links, and more.
  3. Lastly, we're initializing our application with the configuration object we just created.