In this article, we explore Firebase Cloud Messaging (FCM) — covering Firebase Console setup, Android/iOS integration, and Node.js backend implementation. You’ll also learn how to structure payloads and manage notifications in both foreground and background states.
In my project, I used FCM to deliver in-app and push notifications for alerts, reminders, and real-time updates. We utilized FCM’s capabilities like user targeting, topic-based messaging, and custom data payloads to create a seamless cross-platform experience.
This guide aims to provide practical insights and code examples to help you build a reliable, scalable messaging system with FCM.
Why Firebase Cloud Messaging (FCM) is the Best Choice
- Free and Scalable
You can send millions of notifications without worrying about cost — FCM is completely free and handles large volumes easily.
- Works on All Platforms
Whether it’s Android, iOS, or Web — FCM supports all major platforms with just one integration.
- Reliable Delivery
Since it runs on Google’s powerful infrastructure, your messages are delivered quickly and consistently, even at scale.
- Send More Than Just Notifications
FCM allows you to send rich messages — not just titles and bodies, but also custom data (like IDs, URLs, Images) that your app can use to take actions.
- Smart Targeting
You can choose exactly who should receive the message — by device, user group, app version, or custom topics.
- Built-in Analytics and Tracking
FCM comes with delivery reports and integrates with Firebase Analytics, so you know how your messages are performing.
FCM Architecture Overview

- Device Registration:
The mobile device registers with FCM (Android) or APNS (iOS) to obtain a Device Token used for uniquely identifying the app instance.
- Developer Setup:
The developer configures the Firebase project and uploads APNS certificates (for iOS) or uses FCM Server Key (for Android) to authorize message sending.
- Token Sharing:
The app sends the obtained Device Token to the Backend Server or Notification Provider, enabling them to send targeted messages.
- Sending Notifications:
The Backend or Notification Provider sends messages to FCM/APNS, which then delivers them to the appropriate devices using the token.
FCM Message Payload Structure
FCM supports two types of messages:
- Notification Messages (Handled automatically by OS if app is in background).
- Data Messages (Requires app-side handling, useful for in-app updates).
Sample JSON Payload:
{ "message": { "token": "DEVICE_FCM_TOKEN", // FCM token of the target device "notification": { "title": "New Message!", // Title shown in the notification "body": "You have a new notification." //Body text shown in the notification }, "data": { "action": "chat", // Custom key: Used to define app behavior (e.g., open chat screen) "userId": "123" // Custom key: Can be used to identify a specific user or context } } }
Setting Up FCM in Android and iOS
Android Setup:
1. Add Firebase to Android Project
- Go to Firebase Console.
- Add your Android app (com.example.app) and download google-services.json.
- Place it in app/ directory.
2. Add Dependencies (app/build.gradle)
implementation 'com.google.firebase:firebase-messaging:23.0.0'
3. Create a Service to Handle Messages
class MyFirebaseMessagingService : FirebaseMessagingService() { override fun onMessageReceived(message: RemoteMessage) { // Handle notification/data payload here Log.d("FCM", "Message: ${message.notification?.title}") } }
iOS Setup:
1. Add Firebase to iOS Project
- Register your iOS app in Firebase Console.
- Download GoogleService-Info.plist and add it to Xcode.
2. Install Firebase SDK
3. Configure AppDelegate for FCM
Sending FCM Message from NodeJs
1. Setup Firebase Project & Download Admin SDK
- Go to Firebase Console
- Create a new project (or use an existing one)
- Navigate to: Project Settings → Service accounts
- Click Generate new private key
- Save the JSON file (this contains your Firebase credentials)
- Install Firebase Admin SDK
- npm install firebase-admin
2. Initialize Firebase Admin
const admin = require("firebase-admin"); const serviceAccount = require("./service-account-key.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), }); // Send a notification const sendFCM = async (token, title, body, data = {}) => { const message = { token, notification: { title, body }, data, }; try { await admin.messaging().send(message); console.log("Message sent successfully!"); } catch (err) { console.error("FCM Error:", err); } }; // Example usage sendFCM( "DEVICE_TOKEN", "Hello from Node.js!", "This is a test FCM message.", { action: "test" } );
Testing and Sending Notifications
You can test by calling your Node.js API with a valid device token. Use Postman to send a POST request to your backend with parameters like:
{ "token": "DEVICE_FCM_TOKEN", "title": "Hello", "body": "This is a test message." }
Common Issues and Fixes
- Make sure the device token is correct.
- Always handle errors (e.g., invalid tokens, network issues)
- Ensure Firebase is properly initialized in both frontend and backend.
- For iOS, ensure APNs certificates are uploaded in Firebase.
At CoReCo, we specialize in identifying process bottlenecks and turning them into opportunities for innovation. From aviation to logistics to enterprise operations, our team thrives on combining deep domain understanding with practical technology solutions.
Want to explore how your organization can streamline its processes using data, automation, and smart design?
Reach out to us at [email protected]—we’d love to hear from you!