node.js - 是否可以在 node.js 中运行 firebase 消息传递?

标签 node.js firebase firebase-cloud-messaging

在 nodejs 下我做了:

npm install firebase --save

然后我做

  var firebase = require("firebase");

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

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

但是当它说firebase.messaging is not a function

时崩溃了

他们有什么方法可以在 node.js 中运行 firebase 消息来监听通知吗? 它们是文件 /node_modules/firebase/firebase-messaging.js 但它很模糊,我无法理解它以及它的作用

最佳答案

有两个 Firebase SDK 可以在 Node 上运行:

  • Firebase Web SDK ,它针对客户端设备,例如浏览器和 Node.js 物联网设备。
  • Firebase Admin SDK ,它旨在在受信任的设备上运行,例如您托管的 Node.js 服务器。

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

通过 Firebase 云消息传递接收消息的支持包含在 Firebase Web SDK 中。在 Node.js 中无法接收 FCM 消息。

如果您想将消息发送到 Node.js 进程,我建议您查看 Firebase Realtime Database .

关于node.js - 是否可以在 node.js 中运行 firebase 消息传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43936730/

相关文章:

javascript - 进程超时 |亚马逊 Lambda 到 Firebase

javascript - 在多个文件中使用 socket.io

firebase - 如何以非交互方式安装 firebase 扩展

javascript - Firebase 云功能 - 如何解决此错误 : ECONNRESET

firebase - FCM : How to avoid duplicate notifications if a user has subscribed to multiple topics

安卓 : Get the list of images to download added in the separate folder of Firebase console from a FireBase Storage API

node.js - 获取 504 GATEWAY_TIMEOUT NodeJs

node.js - 如何获取正在运行的 Yeoman 生成器的当前路径

node.js - 如何使用 Firebase Cloud Functions 删除旧文件?

ios - Swift - 使用 FireBase 登录 - 登录后无法检索用户数据