Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/http/mod.ts>ServerSentEvent

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
variable ServerSentEvent
Deprecated
Deprecated

(will be removed after 0.210.0) Import from std/http/unstable_server_sent_event.ts instead.

An event which contains information which will be sent to the remote connection and be made available in an EventSource as an event. A server creates new events and dispatches them on the target which will then be sent to a client.

See more about Server-sent events on MDN

Example

import {
ServerSentEvent,
ServerSentEventStreamTarget,
} from "https://deno.land/std@0.206.0/http/server_sent_event.ts";

Deno.serve({ port: 8000 }, (request) => {
const target = new ServerSentEventStreamTarget();
const evt = new ServerSentEvent("message", {
data: { hello: "world" },
id: 1
});
target.dispatchEvent(evt);
return target.asResponse();
});
import { ServerSentEvent } from "https://deno.land/std@0.206.0/http/mod.ts";