Nodejs firebase push notification for android device
letFCM=require('fcm-node');importconfigfrom'../config'varapn=require('apn');letpath=require('path');letfs=require('fs');// Set up apn with the APNs Auth KeyletapnProvider=newapn.Provider({token: {key: fs.readFileSync(path.resolve(__dirname+'/file.p8')),keyId: config.keyId,// The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)teamId: config.teamId,// The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)},production: true// Set to true if sending a notification to a production iOS app});classPushNotification{staticasyncsendAndroid(data){returnnewPromise((resolve,reject)=>{varserverKey=config.serverKey;//put your server key herevarfcm=newFCM(serverKey);varmessage={//this may vary according to the message type (single recipient, multicast, topic, et cetera)to: data.deviceToken,collapse_key: config.collapse_key,notification: {title: data.title,body: data.message},data: {//you can send only notification or only data(or include both)data: data}};fcm.send(message,function(err,response){if(err){console.log("Something has gone wrong!",err);reject(err);}else{resolve(response);console.log("Successfully sent with response: ",response);}});})}}module.exports=PushNotification