Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run firebase messaging in node.js?

under nodejs i did :

npm install firebase --save

then i do

  var firebase = require("firebase");

  // Initialize Firebase
  var config = {
    apiKey: "...",
    authDomain: "...,
    databaseURL: "....",
    projectId: "....",
    storageBucket: "....",
    messagingSenderId: "...."
  };
  firebase.initializeApp(config);

  const messaging = firebase.messaging(); << crash here

but it's crash saying firebase.messaging is not a function

Is their any way to run firebase messaging in node.js to listen notification ? their is the file /node_modules/firebase/firebase-messaging.js but it's obfuscate and i can't understand it and what it's does

like image 779
zeus Avatar asked May 12 '17 11:05

zeus


People also ask

What is FCM token in Nodejs?

What is FCM ? Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably send messages at no cost.

Can we use Firebase to send SMS?

Add Firebase Cloud Messaging to your Android, Apple, or Web app. Set up your trusted environment where you'll build and send message requests.

Is FCM really free?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.


1 Answers

There are two Firebase SDKs that will work on Node:

  • the Firebase Web SDK, which is targeted towards client-side devices such as browsers and Node.js IoT devices.
  • the Firebase Admin SDK, which is meant to run on trusted devices, such as a Node.js server that you host.

Support for sending messages through Firebase Cloud Messaging is only included in the Firebase Admin SDK for Node.js.

Supporting for receiving messages through Firebase Cloud Messaging is only included in the Firebase Web SDK. It is not possible to receive FCM messages in Node.js.

If you want to send message to a Node.js process, I'd recommend you look into the Firebase Realtime Database.

like image 143
Frank van Puffelen Avatar answered Oct 21 '22 05:10

Frank van Puffelen