fcm-traverse
v1.0.3
Published
A straightforward Node.js interface for Google's Firebase Cloud Messaging (FCM) is provided, supporting both Android and iOS platforms. It facilitates topic messages, parallel calls, and maintains callback functionality for the new Firebase Messaging serv
Downloads
4
Readme
FCM-Node
A Node.js simple interface to Google's Firebase Cloud Messaging (FCM). Supports both Android and iOS, including topic messages, and parallel calls. Additionally, it also keeps the callback behavior for the new Firebase Messaging service.
Installation
Via npm:
$ npm install fcm-node
Usage
Classic Usage
Generate Server Key:
Generate a Server Key on your app's Firebase console.
Initialize FCM:
Create an instance of the FCM class by passing your generated server key.
Create Message:
Build a message object with the necessary parameters.
Send Message:
Call the send() function on the FCM instance with the message object.
### Classic usage example:
```
const FCM = require('fcm-node');
const serverKey = 'YOURSERVERKEYHERE'; // Put your server key here
const fcm = new FCM(serverKey);
const message = {
to: 'registration_token',
collapse_key: 'your_collapse_key',
notification: {
title: 'Title of your push notification',
body: 'Body of your push notification'
},
data: {
my_key: 'my value',
my_another_key: 'my another value'
}
};
fcm.send(message, function(err, response) {
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response:", response);
}
});
```