Sending push notifications
Way back at the beginning of this book, when we initialized Firebase, we checked an option for Functions
. This created a folder in our root directory called functions
, which we have ignored as of yet (if you don't have this folder, you can run firebase init
again, and ensure that you check off both Functions
and Hosting
for the first question. Reference the chapter on Firebase for more).
The functions
folder allows us to use Firebase Cloud Functions. Here's how Google defines them:
“Cloud Functions gives developers access to Firebase and Google Cloud events, along with scalable computing power to run code in response to those events.”
That's the simplest definition--code that runs in response to events, outside of our application. We extract a bit of functionality that doesn't belong to any particular instance of our app (because it concerns all instances of our app) to the Cloud, and have it run automatically by Firebase.
Let's open up functions /index.js
and get...