Skip to content

Latest commit

 

History

History
21 lines (15 loc) · 685 Bytes

EventSource.md

File metadata and controls

21 lines (15 loc) · 685 Bytes

EventSource

Undici exposes a WHATWG spec-compliant implementation of EventSource for Server-Sent Events.

Instantiating EventSource

Undici exports a EventSource class. You can instantiate the EventSource as follows:

import { EventSource } from 'undici'

const evenSource = new EventSource('http://localhost:3000')
evenSource.onmessage = (event) => {
  console.log(event.data)
}

More information about the EventSource API can be found on MDN.