Skip to content

Instantly share code, notes, and snippets.

@n1lesh
Created December 23, 2017 09:05
Show Gist options
  • Save n1lesh/75c3f5549540bd81a680ce222e91912b to your computer and use it in GitHub Desktop.
Save n1lesh/75c3f5549540bd81a680ce222e91912b to your computer and use it in GitHub Desktop.
Firebase Cloud Messaging with Node.js - FCM 3
const sendNotifications = (data) => {
const dataString = JSON.stringify(data)
const headers = {
'Authorization': 'key=<your firebase legacy server key>',
'Content-Type': 'application/json',
'Content-Length': dataString.length
}
const options = {
uri: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: headers,
json: data
}
request(options, function (err, res, body) {
if (err) throw err
else console.log(body)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment