Posts

Showing posts from March, 2024

Firebase Push Notification Using NodeJS.

Image
  Step 1: Set up Firebase Project Go to the Firebase Console (https://console.firebase.google.com/) Create a new project or select an existing one. Go to Project Settings -> Cloud Messaging tab. Take note of the Server Key and Sender ID. Step 2: Set up Node.js Project mkdir firebase-push-notifications cd firebase-push-notifications npm init -y npm install firebase-admin Step 3: Write the Code Create a file named index.js and add the following code: const admin = require('firebase-admin'); // Initialize Firebase Admin SDK const serviceAccount = require('./path/to/serviceAccountKey.json'); // Path to your service account key file admin.initializeApp({   credential: admin.credential.cert(serviceAccount), }); // Send a push notification function sendPushNotification(token, title, body) {   const message = {     notification: {       title: title,       body: body,     },     token: token,   };   admin.m...