How to Resolve JavaScript Promises Sequentially (one by one)

Let’s say you have a set of asynchronous tasks to do. task1() task2() task3() All three tasks do some operation and then return a promise. What these tasks actually do is not really important just now. We can, for now, just assume that they return a Promise at least. We know that if we execute […]

How to Convert Realtime Database Events to Promises in Firebase

firebase

The Realtime Database API in Firebase is based on callbacks. This could be fine for you if you are maintaining a codebase which is a few years old. But, if you prefer a Promise, or better yet async await approach, you will be down for a little disappointment. A typical function that you write for retrieving data from […]

Retrying Failed HTTP Requests in Node.js

nodejs

Relying on 3rd party services to handle some part of your business logic is a common practice. You might use SendGrid to send emails, Google Cloud Bucket Storage API to store some binary blob or Twilio for sending SMS to your users. Although, the three I mentioned above are quite reliable, you might find yourself […]

Create User Profile in Firestore After Authentication in Firebase

firebase

When a user signs up for your app, Firebase creates their profile in Firebase Authentication. This is great because most of the hard stuff like OAuth and validation is being handled automatically for you. This, however, has its limitations. Auth doesn’t let you store any custom properties to the user and this is very limited […]

How to Split Firebase Cloud Functions for Better Code Organization

firebase

Often times, you may hear that for Node.js development, the code logic should be separated into different modules. This is logical and obviously the best practice whenever you are writing code for the real world. In Firebase Cloud Functions, you can also do that. From your index.js file, simply require() the function from another file and use its reference to […]

Get All Users From Auth in Cloud Functions for Firebase

firebase

To get all the users from auth in Firebase, you can use the Admin SDK for Firebase. It gives you elevated privileges to perform operations in the system that a normal user can not. The Admin SDK comes with a lot of functionality built-in. But, the one thing that we care about here is Managing Users. Getting Users […]

How to Import Large Amount of Data to Cloud Firestore

firebase

Firestore has been out of beta for some time now. But it still doesn’t support import or export functionality natively. This is a big downer for someone wanting to use the native functionality of the Firebase platform. Keep in mind that when I talk about enabling exports/imports, I’m talking about the firebase-admin SDK. Export/Import via the gsutil command-line utility is […]

How to Enable CORS in Node.js Without Express CORS Middleware

It’s very easy to simply install the cors middleware to handle all the CORS stuff while using Node.js as your backend. This, however, leaves you with a very superficial understanding of how the Cross-Origin Resource Sharing mechanism works. In this article, we will add CORS to a very simple http server in Node.js without using Express or […]