The firebase-functions
package provides an SDK for defining Firebase Functions.
In your Firebase project's functions
directory, run:
npm install firebase-functions
// functions/index.js var functions = require('firebase-functions'); var notifyUsers = require('./notify-users'); exports.newPost = functions.database() .path('/posts/{postId}') .onWrite(function(event) { // only execute function on creation if (!event.data.previous.exists()) { notifyUsers(event.data.val()); } });