Skip to content

Instantly share code, notes, and snippets.

@toluolatubosun
Last active March 11, 2023 13:37
Show Gist options
  • Save toluolatubosun/039a21a584436a0cdb304ad48b473003 to your computer and use it in GitHub Desktop.
Save toluolatubosun/039a21a584436a0cdb304ad48b473003 to your computer and use it in GitHub Desktop.
Send Firebase Cloud Message with Node.js
import FirebaseAdmin from "firebase-admin"
const usersNotificationTokens = ["..."]
const serviceAccount = await import("./firebase.json");
FirebaseAdmin.initializeApp({
credential: FirebaseAdmin.credential.cert({
projectId: serviceAccount.project_id,
clientEmail: serviceAccount.client_email,
privateKey: serviceAccount.private_key, // Ensure you are using Node v 18.0.0 or higher to avoid errors reading the private key
})
});
await FirebaseAdmin.messaging().sendMulticast({
tokens: usersNotificationTokens,
notification: {
title: "Hello World",
body: "This is a demo notification",
imageUrl: "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment