Reader small image

You're reading from  Firebase Cookbook

Product typeBook
Published inNov 2017
PublisherPackt
ISBN-139781788296335
Edition1st Edition
Right arrow
Author (1)
Houssem Yahiaoui
Houssem Yahiaoui
author image
Houssem Yahiaoui

Houssem Yahiaoui is a Telerik Developer Expert, Google Developer Group Lead, Meetup organizer, Conference Speaker, and Technical blogger among a few things. He has been a developer since the age of 14 and Firebase lover since day one. He's also a passionate JavaScript developer and strongly believes that JavaScript should fix the World's hanger problem.
Read more about Houssem Yahiaoui

Right arrow

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 
workflow
const firebase = require('firebase');

// [*] 2:Initialising our application with our
credentials
var config = {
apiKey: "<API_KEY>",
authDomain: "<PROJECT_ID>.firebaseapp.com",
databaseURL:
"https://<DATABASE_NAME>.firebaseio.com",
storageBucket: "<BUCKET>.appspot.com",
};
firebase.initializeApp(config);

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.
Previous PageNext Page
You have been reading a chapter from
Firebase Cookbook
Published in: Nov 2017Publisher: PacktISBN-13: 9781788296335
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Houssem Yahiaoui

Houssem Yahiaoui is a Telerik Developer Expert, Google Developer Group Lead, Meetup organizer, Conference Speaker, and Technical blogger among a few things. He has been a developer since the age of 14 and Firebase lover since day one. He's also a passionate JavaScript developer and strongly believes that JavaScript should fix the World's hanger problem.
Read more about Houssem Yahiaoui