[英]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.