Skip to content

Instantly share code, notes, and snippets.

@n1lesh
Created December 23, 2017 09:06
Show Gist options
  • Save n1lesh/c3687cdad6fc12706ea05037f9fe4302 to your computer and use it in GitHub Desktop.
Save n1lesh/c3687cdad6fc12706ea05037f9fe4302 to your computer and use it in GitHub Desktop.
Firebase Cloud Messaging with Node.js - FCM 6
app.post('/notify', (req, res) => {
let msg = req.body.message,
title = req.body.title,
type = req.body.type,
topic = req.body.topic
if (type === 'topic') {
sendToTopics(msg, title, topic, res)
} else {
MongoClient.connect(url, function (err, db) {
if (err) throw err
else {
db.collection('tokens').find({}).toArray((err, docs) => {
sendToAll(msg, title, docs, res)
})
}
db.close()
})
}
})
app.listen(8000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment