Send Push Notification from mongodb function using firebase


I am trying to send push notification from mongodb function using firebase (fcm).

I have the following code working on node.js, which i am trying to replicate in function:
const admin = require(‘firebase-admin’);
let serviceAccount = require(’./serviceAccountKey.json’);
credential: admin.credential.cert(serviceAccount)

Uploaded all the relevant external dependencies.

Now, the problem is i don’t know how the following code will work:
let serviceAccount = require(’./serviceAccountKey.json’);

this line is looking for external json file (unfortunately, not able to upload it as dependencies)

Any help to make it work would be appreciated.


1 Like


If you set your Sender Id and API Key under Push Notifications -> Config you can use following function to send notifications:

exports = function(deviceToken){
  // Construct message
  const message = {
    "to": deviceToken,
    "notification": {
      "title": "Test Title",
      "body": "Test Message"
  // Send push notification
  const gcm ='gcm');
  const result = gcm.send(message);
  return result;