eventsource-client is a modern, streaming client for Server-Sent Events (SSE) that operates across both Node.js and browser environments. The package is currently at version 1.2.0 and maintains an active release cadence, with multiple minor updates and bug fixes released throughout the year. It distinguishes itself from traditional EventSource polyfills by not aiming for API compatibility with the browser's native EventSource API. Instead, it offers a more flexible and robust approach, leveraging modern web APIs like `fetch()` and Web Streams. Key differentiators include support for async iterator patterns, various HTTP request methods (POST, PATCH, DELETE), custom headers, request bodies, configurable reconnection policies, and the ability to subscribe to any event name, including the `error` event, along with setting an initial `Last-Event-ID`. The library ships with both ESM and CommonJS versions for broad compatibility.
npm install eventsource-clientVerified import paths — ran on the pinned version, not inferred.
Demonstrates connecting to an SSE endpoint using `createEventSource` with callback handlers for messages, connection status, and errors. Also highlights explicit connection closing.
Upgrade your Node.js environment to version 18 or newer, or ensure you are using a compatible runtime like modern browsers, Deno, or Bun. If using an older Node.js, you might need to polyfill `fetch` and `ReadableStream`.
Review the documentation for `createEventSource` options and its return object (especially the async iterator pattern) to understand its distinct API.
Always include `es.close()` after your `for await...of` loop, or within error handling, to ensure the connection is properly terminated.
Pass your chosen `fetch` polyfill or implementation as the `fetch` option: `createEventSource({ url: '...', fetch: yourFetchImpl })`.Upgrade your Node.js environment to v18+ or provide a `fetch` implementation (e.g., `node-fetch`) via the `fetch` option in `createEventSource`.
Ensure you are using `import { createEventSource } from 'eventsource-client'` for ESM or `const { createEventSource } = require('eventsource-client')` for CommonJS, and that your build setup correctly handles module resolution.Ensure your environment supports `Symbol.asyncIterator` (Node.js >= 18, modern browsers). If issues persist, consider using the callback-based `onMessage` API instead of the async iterator.
No dependency data recorded yet.