Home > Enterprise >  how to send firebase topic notification in node and express?
how to send firebase topic notification in node and express?

Time:09-30

I want to send notification all users in app, Android developer subscribed topic name with ALL_USER but I am not able to send notification to that topic.

Thanks for help in Advance.

CodePudding user response:

Try this -

  1. From your firebase project download the JSON file which contains the server key and places it in the root folder privatekey.json.

  2. Use the below code in your API or function.

var fcm = require('fcm-notification');
var FCM = new fcm('./privatekey.json');

var message = {
    topic: topic,
    notification: {
      title: title,
      body: body
  }
  };

  FCM.send(message, function (err, response) {
    if (err) {
      console.log("Something has gone wrong!"   err);
    } else {
      console.log("Successfully sent with response: ", response);
    }
  });
  • Related