0

I'm really interested in the synchronized database paradigm championed by Firebase and others (Couchbase Sync Gateway for example). It really does a great job in replacing 80% of what an API does, which is storing and retrieving data. But usually, that's not all an API does. While we are storing and retrieving data, we are also doing non-data related stuff like sending emails or push notifications. To do those things, I should be able to intercept data changes and do something when a new record is created, when an existing record is changed in a certain way, or when a record is deleted. Parse has a great mechanism for that in its Cloud Code (https://parse.com/docs/cloud_code_guide#functions-aftersave) but I couldn't find something similar in Firebase. Did I miss something or am I thinking of it the wrong way?

Sebastien
  • 2,503
  • 2
  • 31
  • 68
  • 2
    When using Firebase you'd set up a separate client/server that handles those additional tasks. So if you want to send a welcome email to new users, you'd set up a Firebase client that listens for new users, sends an email to them and (probably) marks that it has sent that email. This service would normally run under some elevated admin account, or by using the main *secret* of your Firebase. – Frank van Puffelen Nov 19 '14 at 19:33
  • You can also use a service like Zapier to trigger those events from Firebase and soon, Firebase will have built-in triggers to push notices out to third parties. – Kato Nov 20 '14 at 16:47
  • Zapier is nice but I was more thinking in terms of custom code to be run. Push notification are an easy example but sometimes you need to integrate with a third party-service, call a REST API somewhere and so on. So running another client to do those sort of things seems more adapted but it's sad that Firebase doesn't offer this sort of cloud code capabilities. – Sebastien Nov 21 '14 at 17:49
  • For such purposes, maybe [Firebase Functions](https://stackoverflow.com/questions/42616809/sending-automated-emails-from-firebase-through-google-cloud-platform-no-third-p) would help a lot. Indeed, there's a solution specifically for sending Emails mentioned in that solution linked. – DavidTaubmann Jul 05 '19 at 01:32

1 Answers1

0
    firebaseRef.on('child_changed', function(childSnapshot, prevChildKey) {
  // code to handle child data changes.
});

This is the article : https://www.firebase.com/docs/web/api/query/on.html child_change event

Miguel Peguero
  • 299
  • 3
  • 4