JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16773
  • Score
    100M100P100Q129190F
  • License GNU LGPLv3

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages, and parallel calls

Package Exports

  • fcm-node

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fcm-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM). Supports both android and iOS, including topic messages

Installation

Via npm:

$ npm install fcm-node

Usage

var FCM = require('fcm-node');

var serverKey = '';
var fcm = new FCM(serverKey);

var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
    to: 'registration_token', 
    collapse_key: 'your_collapse_key',
    
    notification: {
        title: 'Title of your push notification', 
        body: 'Body of your push notification' 
    },
    
    data: {  //you can send only notification or only data(or include both)
        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);
    }
});

Notes

  • See FCM documentation for general details.
  • See Firebase Cloud Messaging HTTP Protocol for details about the HTTP syntax used and JSON fields, notification and data objects. (STRONGLY RECOMMENDED)
  • On iOS, set content_available when the app server needs to send a Send-to-Sync message. An inactive client app executes your logic in the background, while an app in the foreground passes the message to didReceiveRemoteNotification. (As seen in FCM Docs)
  • Some iOS users report a delay receiving the notifications and even a 'not receive at all' scenario if the priority field is not set. This is due to a delivery policy with APN (See APNs Provider API for a more detailed info)

Credits

Extended by Leonardo Pereira. Based on the great work on fcm-push by Rasmunandar Rustam cloned and modified from there, which in its turn, was cloned and modified from Changshin Lee's node-gcm

License

GNU LESSER GENERAL PUBLIC LICENSE v3

Changelog

1.0.13 - Added a error response in case of TopicsMessageRateExceeded response 1.0.12 - Refactored the client removing the Event Emitter's Logic to fix concurrency issues. Using pure callbacks now also avoids memory leak in specific scenarios with lots of parallel calls to send function.
1.0.11 - <FIX> send function returning error objects when multicast messages (or individually targeted) returned both error and success keys on response message (even with error counter = 0 )
1.0.9 - Updated Documentation
1.0.8 - <FIX> 'icon' field no longer required in notification
1.0.7 - renaming repository
1.0.6 - bugfix: send function was always returning an error object for multicast messages (multiple registration ids)
1.0.5 - bugfix with UTF-8 enconding and chunk-encoded transfers
1.0.1 - forked from fcm-push and extended to accept topic messages without errors