Skip to content

Instantly share code, notes, and snippets.

@tomcurran
Created February 28, 2023 17:48
Show Gist options
  • Select an option

  • Save tomcurran/9e558752e6ae2fa51aecd244f5b02eb7 to your computer and use it in GitHub Desktop.

Select an option

Save tomcurran/9e558752e6ae2fa51aecd244f5b02eb7 to your computer and use it in GitHub Desktop.
Firebase Messaging Test
const admin = require("firebase-admin");
const serviceAccount = require("./service-account.json");
const registrationToken = "REGISTRATION_TOKEN_1";
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
});
const message = {
notification: {
title: 'Notification title test',
body: 'Notification subtitle test'
}
};
admin.messaging().sendToDevice(registrationToken, message)
.then((response) => {
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
{
"dependencies": {
"firebase-admin": "^10.0.2"
}
}
{
"type": "service_account",
"more": "properties"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment