简体   繁体   English

如何从节点 js 应用程序向客户端发送实时更新

[英]how to send realtime updates to client from node js app

I am using firebase realtime database and firebase firestore in my web app and everytime a user updates their data firebase is sending that data to my server and I want to send that data to client how do it do it because with my current code it is giving me res.setHeader error I am using firebase realtime database and firebase firestore in my web app and everytime a user updates their data firebase is sending that data to my server and I want to send that data to client how do it do it because with my current code it is giving我 res.setHeader 错误

What you're looking for is called realtime updates, which use onSnapshot .您正在寻找的是使用onSnapshot的实时更新。

Here is the relevant tutorial https://firebase.google.com/docs/firestore/query-data/listen这里是相关教程https://firebase.google.com/docs/firestore/query-data/listen

The example there for NodeJS is: NodeJS 的示例是:

const doc = db.collection('cities').doc('SF');

const observer = doc.onSnapshot(docSnapshot => {
  console.log(`Received doc snapshot: ${docSnapshot}`);
  // ...
}, err => {
  console.log(`Encountered error: ${err}`);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Node.js 从 Firestore 实时更新 - Realtime updates from Firestore via Node.js 从 Node.js 中的 Firebase 实时数据库中选择特定属性 - Select specific properties from Firebase Realtime Database in Node.js 如何添加角色以允许实时数据库更新 - How to add a role to allow updates in realtime database 如何在Flutter中实时更新Firebase? - How to make realtime list updates Firebase in Flutter? 如何在客户端自动从后端获取更新 - How to get updates from backend automatically in client side 如何从常规的基于 html/js 的应用程序调用节点应用程序? - How to call node app from regular html/js based application? 如何从firebase实时数据库中删除选中的item节点? - How to delete selected item node from firebase realtime database? 如何在应用程序启动时阻止 Firebase 记录状态更新 - How to stop Firebase from logging status updates when app is launched 如何在 React JS 中从 firebase 实时数据库中获取数据 - How fetch data from firebase realtime database in react js 如何将序列化的 object 从 Android 客户端发送到 Google App Engine Servlet? - How to send serialized object from Android Client to Google App Engine Servlet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM