The `event-stream-parser` package provides a lightweight, zero-dependency implementation for parsing Server-Sent Events (SSE) streams, strictly adhering to the HTML Living Standard specification. Designed to leverage the Web Streams API, it offers full compatibility with modern web browsers and Node.js environments (requiring Node.js >=18.0.0). The current stable version is `1.0.2`, with a release cadence that has been fairly rapid since its initial v1.0.0 release in early 2024. Its key differentiators include its minimalistic design, native Web Streams integration for efficient processing, and comprehensive TypeScript support, making it an ideal choice for applications requiring robust and standards-compliant SSE consumption without external bloat.
npm install event-stream-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to fetch a Server-Sent Events stream using `fetch`, parse it with `event-stream-parser`, and consume the resulting `MessageEvent` objects via a `WritableStream`.
Use `const eventStream = await parse(response.body);` instead of `const eventStream = parse(response.body);`
Upgrade your Node.js environment to version 18 or newer (e.g., `nvm install 18 && nvm use 18`).
Ensure your `fetch` request includes `{ headers: { Accept: 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' } }`.Use `import { parse } from 'event-stream-parser';` for importing. Ensure your Node.js version is >=18 and your project is configured for ESM (e.g., `"type": "module"` in `package.json`).Verify the server endpoint is correctly configured to send Server-Sent Events, and ensure your `fetch` request includes the `Accept: 'text/event-stream'` header.
Always `await` the result of the `parse` function: `const eventStream = await parse(response.body);`.
No dependency data recorded yet.