Skip to content

Instantly share code, notes, and snippets.

@ikishanoza
Created March 27, 2019 10:28
Show Gist options
  • Save ikishanoza/28c3330f7a99af39a4913317d6c6dedb to your computer and use it in GitHub Desktop.
Save ikishanoza/28c3330f7a99af39a4913317d6c6dedb to your computer and use it in GitHub Desktop.
fcm for nodejs
var request = require('request');
function sendMessageToUser(deviceId, message) {
request({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type' :' application/json',
'Authorization': 'key=AI...8o'
},
body: JSON.stringify(
{ "data": {
"message": message
},
"to" : deviceId
}
)
}, function(error, response, body) {
if (error) {
console.error(error, response, body);
}
else if (response.statusCode >= 400) {
console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage+'\n'+body);
}
else {
console.log('Done!')
}
});
sendMessageToUser(
"d7x...KJQ",
{ message: 'Hello puf'}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment