October 2017
Intermediate to advanced
302 pages
7h 27m
English
First, we can initialize our app, as follows:
const functions = require('firebase-functions');const admin = require('firebase-admin');admin.initializeApp(functions.config().firebase);
Cloud functions = code run in response to events, so what's our event?
We want to notify the user when a new message is created. So, the event is a new message, or, more specifically, when a new entry is created in the messages table of our database.
We'll define the export of our index.js to be a function called sendNotifications, which defines a listener for the onWrite event of /messages:
exports.sendNotifications = functions.database .ref('/messages/{messageId}') .onWrite(event => {});
Everything else in this section will take ...
Read now
Unlock full access