Back to Blog
Backend•8 min read
Building a Real-Time Notification System in Node.js with Firebase
Arjun Singh
Backend Lead
Jan 28, 2026
Push notifications are essential for user retention. In this guide, we will set up a Node.js Express server that triggers Firebase Cloud Messaging (FCM) to send notifications.
Step 1: Setup Firebase Admin SDK
javascript
const admin = require("firebase-admin");
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
module.exports = admin;Step 2: Sending the Notification
javascript
const sendNotification = async (token, title, body) => {
try {
const message = {
notification: { title, body },
token: token
};
const response = await admin.messaging().send(message);
console.log("Successfully sent message:", response);
} catch (error) {
console.log("Error sending message:", error);
}
};Share this article:
