Staring into the Firebase

Staring into the Firebase

The user interface of your app is the front-end, like the beautiful space you sit in at a restaurant. But you also need a backend - the kitchen that makes the food, the pantry that stores ingredients, etc. This is where Google Firebase comes into play.

Firebase is a Backend-as-a-Service. It allows you to connect a database to your app, and Firebase works in real time, which is why it works well for apps where students interact with each other. But it doesn't stop there. It provides an authentication service. You can host your app through Firebase. It has cloud functions that, for example, automatically clean up old sessions so they do not take up space. Firebase's functionality is pretty amazing. And most LLMs seem to prefer it for writing code; Codex, Claude, and Gemini are usually very comfortable integrating your code with Firebase and writing Firebase cloud functions and rules. You can deploy your code to Firebase for hosting, push new functions to Firebase, and update the rules that govern your Firebase, all from your terminal.

You will need a Google Account to use Firebase. But from the Firebase console (console.firebase.google.com), you can easily create a new project for your app. Within the project in Firebase, you create an App. (This sounds confusing; you create an App Firebase, but you also create the code for your App using an LLM, and that code is stored in a Project Folder on your hard disk.) You can have multiple Firebase Apps share the same Project, but I found this troublesome; the Firebase rules apply to all Apps in a Project, so I usually match each App to its own Firebase Project.

In the Firebase Project Overview, you can hit the build button to access several shortcuts for your project. The useful ones are the Firestore Database (needed to record, store, and share data in real time), Hosting (to publish your app), Authentication (to register users), App Check (for security, so nobody else can use your Firebase), and Functions (to create functions that run autonomously on the server side).

Firebase has a no-cost plan (called Spark, see https://firebase.google.com/pricing) and a pay-as-you-go plan (called Blaze). The latter includes the free functionality of the no-cost plan, but it will charge you once usage goes beyond the no-cost plan. If you use Firebase Functions, you will need the Blaze plan. I usually go that route with my apps. For my beer game app, I can run it with about 200 students per day without hitting the usage limits that would trigger charges. Google makes it easy to build small applications for non-commercial purposes. But if you build your app for much higher usage, you will need to be careful not to get charged under the pay-as-you-go plan. If you want to be safe, stick with Spark.

Connecting an App to Firebase requires a few things. As a first step, the code your LLM created usually has an .env file that contains key information the app needs to connect to services. If you check the settings of the App you created in Firebase, you will see a bunch of connection parameters, such as apiKey, authDomain, projectID, etc. You basically copy and paste these parameters into the .env file in your IDE.

To proceed, you need to install Node.js on your computer. You can find the Windows installer at https://nodejs.org/en. Think of Node.js as the hyper-efficient chef you hire for your kitchen. It is a runtime environment that uses JavaScript to handle interactions with Firebase. JavaScript used to be just a Front-End language, but you can now handle the entire App in JavaScript (or TypeScript, a modern derivative) thanks to Node.js. It is also an incredible multitasker. Last but not least, it is a recipe book, which is what npm stands for. You can simply download many pre-coded recipes for your app using npm install in your terminal. One tip: when you install Node.js, the installer asks you to install additional software as well; don't do that, you generally don't need it, and it will just take up space on your hard disk.

Now, you can go through a few simple steps to set up Firebase in your terminal:

  • 'npm install firebase' will install Firebase in your project folder
  • 'npm install -g firebase-tools' will install several tools related to firebase in your folder
  • 'firebase login' will allow you to login to your Google account to connect to Firebase
  • 'firebase init' will initialize Firebase and setup some services; usually, you want Hosting, Firestore and maybe Functions.
  • 'firebase deploy' will deploy your app for web hosting (only do this when you are ready for your app to be available in public; use a localhost before to test it out, I will describe that work loop in a later post)

If you use Firebase Functions, you have to repeat 'npm install' in the functions folder of your project, and enter 'firebase deploy --only functions' to deploy these functions to Firebase. Similarly, you may need to set rules for Firebase. If your LLM has created these rules (look for a file called firestore.rules), you can use 'firebase deploy --only firestore:rules' to deploy these rules. If, for some reason, deploying these rules doesn't work, you can access them manually in your Firebase Console. Go to the Firestore Database of your Project, and hit the 'Rules' tab. You can edit the rules there, or copy and paste from your Project Folder.

This seems complicated, but in the end, it's a simple routine. I use Firebase for all my projects, and find it very easy to use and quite effective.