Day 5 Sending Firebase Notification using Nodejs
By Sulthan Allaudeen ·
Once you're setup with the firebase in your application, you can send push notification through any source, I am using Nodejs.
Step 1 : Install FCM in node project Go here https://www.npmjs.com/package/fcm or add
From your terminal
npm install fcm
Step 2 : Include fcm in your controller
var FCM = require('fcm-push');
Step 3 : Configure fcm in your project
var fcm = new FCM(serverKey);
Step 4 : Trigger / Push the push notification
var message = {
to: fcm_token
collapse_key: pid,
notification: {
title: "title",
body: message
}
};
fcm.send(message, function(err, response) {
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response: ", response);
}
});
to: fcm_token
collapse_key: pid,
notification: {
title: "title",
body: message
}
};
fcm.send(message, function(err, response) {
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response: ", response);
}
});
Now you're done !
Topics: Mobile Apps, APIs & Automation, JavaScript