Easy real-time communication
Operates directly over HTTP.
No pinging, long-polling or WebSockets required.
Easy real-time communication
Operates directly over HTTP.
No pinging, long-polling or WebSockets required.
Multi-client broadcasting
Send events to individual clients or to many at once using broadcast channels.
Web standards compliant
Full compliance to the WHATWG SSE specification.
Support for modern web frameworks that use the Fetch API.
Event batching
Batch and send multiple events in a single transmission to improve performance and lower bandwidth usage.
First-class TypeScript
Written in TypeScript and ships with types directly.
Define types for state and event data.
Highly configurable
Modify reconnection time, message serialization, data sanitization, response headers and more (with good defaults.)
import { createSession } from "better-sse"
app.get("/sse", async (req, res) => { const session = await createSession(req, res) session.push("Hello world!")})
const es = new EventSource("/sse")
es.addEventListener("message", ({ data })) => { const contents = JSON.parse(data) console.log(contents) // Hello world!})