Node Firebase Push Notification is an npm package that simplifies sending push notifications using Firebase Cloud Messaging (FCM) in Node.js applications.
To install the package, use npm:
npm install node-firebase-push-notification
const { FirebaseAdmin } = require('node-firebase-push-notification');
// Initialize FirebaseAdmin with your credentials
FirebaseAdmin.initialize({
projectId: 'your-project-id',
privateKey: 'your-private-key',
clientEmail: 'your-client-email',
databaseURL: 'your-database-url'
});
// Get the FirebaseAdmin instance
const firebaseAdmin = FirebaseAdmin.getInstance();
// Send push notifications to a list of device tokens
firebaseAdmin.sendMulticastMessaging(
['deviceToken1', 'deviceToken2'],
'Notification Title',
'Notification Body',
{ customData: 'value' },
)
.then((batchResponse) => {
console.log('Push notification sent:', batchResponse);
})
.catch((error) => {
console.error('Error sending push notification:', error);
});
Please remember to replace the placeholders such as 'your-project-id'
, 'your-private-key'
, 'your-client-email'
, 'your-database-url'
with the appropriate values for your project.
Contributions are welcome! Please follow the contribution guidelines before submitting a pull request.
This package is MIT licensed.