Reputation: 151
We can simply write some code to fire an event:
res.send("data: " + data + "\n\n");
But SSE has other features, like Last-Event-ID, keep-alive, and so on.
Upvotes: 2
Views: 234
Reputation: 100120
Most SSE features are so simple, that a library would be series of 1-liners:
function send_sse_event(res, data) {
res.write("data: " + data.replace(/\n/g, "data: ") + "\n\n";
}
function get_last_event_id(req) {
return req.headers['last-event-id'];
}
function set_sse_reconnection_delay(res, ms) {
res.write("retry: " + ms);
}
You can use SSE without a library without feeling guilty that you're reinventing the wheel.
Upvotes: 1