Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save malikkurosaki/e8529e35cabf1b382b94e3a66a1d7d60 to your computer and use it in GitHub Desktop.
Save malikkurosaki/e8529e35cabf1b382b94e3a66a1d7d60 to your computer and use it in GitHub Desktop.
firebase notification background node js

notify

var FCM = require('fcm-node');
    var serverKey = 'AAAAJAbKJv0:APA91bGr080z-1rCOJZ04ekn0jvp6v1j9qYR1C_J7Wcw0OF3eBV9tIwxjdb0jOKd0sMbEDtHLvm3NFRWf8vMEjRXNNEAbBl-HQ5ngx0vy0mHV67zv4cz_HjpM6W8qXOPd5Ho9iMsu-eW'; //put your server key here
    var fcm = new FCM(serverKey);
 
    var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
        to: 'c9Q01LpapG8:APA91bFdoUnkz9TqA6h9v938sk8KvNVYKgURjI4EzaPR2sIhozi92cAa6EmReVxzrC2GtUoVD-otkOqjVEkVvACeD1cbePOnWi7QlkZbW0DL5wftfXuevNR0MABSAd0wefyBY0d3CLgy', 
        collapse_key: 'BKo56bL3D5vmsZViDLjpZvtr9x4pDRdfLxWSe1xITLx4IWoRZtebJQslWMeHXJcTm_filU8qWY0RAE7ZquTqcJM',
        
        notification: {
            "body"  : "NOTIFICATION BODY",
            "title" : "NOTIFICATION TITILE",
            "sound" : "default"
        },
        
        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);
        }
    });
    
    ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment