Firebase push notification when new data is added in Database


How do I send notification to all users that have my app either on foreground or background?

for example, I have a seperate app that adds data on firebase, lets call it “post”. Every added post will be displayed in the users app with a listview. Could it be possible that whevener I add a post, all the users will recieve push notification either on foreground or background?

also i took reference with the following:

and have seen similar topics here.


i got the same problem. the way we send notification through API is make all user register to same topics (for example ‘new data’. so when you want to send to all user you just send it to topics and all user subscribe to topics ‘new data’ will receive notifications. But the problem is i dont know how to register topic with push plugin.


Hi @shafrudin, to subscribe the user to a topic you should following this:

once subscribed you can send them notifications through firebase console:

Firebase > Project Overview > GROW > Cloud Messaging

If you want to send them notifications through another app for convenience.
heres the code I used to notify them together with firebase push new data function.

delcare this first:
const httpModule = require("http");

                url: "",
                method: "POST",
                headers: {'Authorization': 'key=AIzaSyA95mMSnwSIbahgZ8ebnUxxxxxxxxxxxxxxx', 'Content-Type': 'application/json' },
                content: JSON.stringify({
                    "notification" : {
                        "body": "Notication description",
                        "title": "Notification Title",
                        "sound": "default",
                        "priority": "High",
                        "time_to_live": "172800", 

                    'to': "/topics/advisory" // its is mandatory to have /topics/ before the topic name
            }).then(function(response) {
                //const result = response.content.toJSON();
            }, function (e) {
                  console.log("Error occurred " + JSON.stringify(e));
      function (result) {
        console.log("created key: " + result.key);

here are some references:

for notification options:



Thanks broo. I did it.