Firebase notification admin.messaging() is not a function - Firebase cloud messaging

Viewed 12

Here is my code

var admin = require("firebase-admin");

var serviceAccount = require("./google-services.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

module.exports.admin = admin

My API file code

const admin = require('../firebaseConfig')

async function sendFireBaseNotification(registrationToken , message  ){

  const options =  notification_options

  return admin.messaging().sendToDevice(registrationToken, message, options)
  .then( response => {

    console.log("Notification sent successfully"+response)
    
  })
  .catch( error => {
      console.log(error);
  });
}

my firebase version "firebase-admin": "^5.13.1" I am getting error 'TypeError: admin.messaging is not a function' I am looking for the solutions , please help.

1 Answers

Version 5.13.1 of the Firebase Admin SDK that you're using is from July 2018 (!). I recommend upgrading to a more recent version.

Related