I'm new to server sent events
,
I red trough many tutorials and watched many helpful videos and I still don't understand "what to do with the data that keep growing on every user request" ??.
I use NodeJS
so I started here..
How To Use Server-Sent Events in Node.js to Build a Realtime App
this following example was taken from the above link..
// in the following function they push each fact to facts array in order to later send it to the client
// the FACTS array can grow and grow and ... ??
async function addFact(request, respsonse, next) {
const newFact = request.body;
facts.push(newFact);
respsonse.json(newFact);
return sendFactToAll(newFact);
}
// this is optimal, only 1 fact is send.
function sendFactToAll(newFact) {
clients.forEach(client =>
client.response.write(`data:${JSON.stringify(newFact)}\n\n`))
}
// what about sending all facts
function sendFactsToAll(facts) {
clients.forEach(client =>
client.response.write(`data:${JSON.stringify(facts)}\n\n`))
}
- when to clear the FACTS array?
- if clearing the array, what about those users who need to get the data from that array?
THANK YOU!