undici exports anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
EventSource class that implements the WHATWG EventSource API for receiving server-sent events (SSE) in Node.js. It supports custom dispatchers, making it possible to add authentication headers, route through proxies, or configure TLS — capabilities not available in browser EventSource.
Constructor
The URL of the SSE endpoint. Must be HTTP or HTTPS.
Optional configuration object.
Basic usage
Receiving server-sent events
Using a custom dispatcher
Pass a custom dispatcher to add headers, use a proxy, or configure TLS:Custom headers via dispatcher
Properties
Current connection state:
0 (CONNECTING), 1 (OPEN), or 2 (CLOSED).The URL of the event source.
Whether the connection was created with credentials.
Event handlers
| Handler | Fires when |
|---|---|
onopen | Connection is established |
onmessage | A message event with no event field is received |
onerror | An error occurs or the connection is lost |
addEventListener:
Closing the connection
SSE message format
The server must respond withContent-Type: text/event-stream. Each message follows the SSE format:
For more details on the EventSource API, see MDN EventSource.