npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sse-events-2

v1.0.4

Published

Forked from Ore by Timothy Ogbemudia, SSE Events 2 is a modern, lightweight TypeScript library for robust streaming and Server-Sent Events (SSE) consumption. It provides a simple, bulletproof API for handling streams with automatic retries and easy integr

Readme

SSE Events 2

Forked from Ore by Timothy Ogbemudia, SSE Events 2 is a modern, lightweight TypeScript library for robust streaming and Server-Sent Events (SSE) consumption. It provides a simple, bulletproof API for handling streams with automatic retries and easy integration into Node.js server-side code.

Unlike Ore, this is not for integration into client-side code.

Specific to my needs, this fork uses the node:http2 client to open streams. There are other solutions published if you can use http1.

Features

  • Bulletproof Streaming: Robust handling of connection drops with automatic retries.
  • Dual Mode:
    • stream(): For raw text/byte streaming (e.g. AI responses, logs).
    • streamSSE(): For spec-compliant Server-Sent Events parsing.
  • Modern API: Uses Async Generators for clean, modern usage (for await...of).
  • Build for Node.js: Works in Node.js (not your browser).
  • Zero Dependencies: Tiny footprint.

Install

npm install sse-events-2

Usage

Raw Streaming (Text/Bytes)

Perfect for AI chat streams, logs, or custom protocols.

import { stream } from "sse-events-2";

// Basic usage
for await (const chunk of stream("http://api.example.com/chat")) {
  console.log(chunk); // "Hello", " world", "!"
}

// With options
const ac = new AbortController();
const dataStream = stream("http://api.example.com/chat", {
  headers: { "Authorization": "Bearer token" },
  retries: 3,
  signal: ac.signal,
  decode: true, // Set to false to get Uint8Array
});

for await (const chunk of dataStream) {
  // ...
}

Server-Sent Events (SSE)

Parses standard SSE format (data: ..., event: ..., id: ...).

import { streamSSE } from "sse-events-2";

for await (const event of streamSSE("http://api.example.com/events")) {
  console.log(event.id);
  console.log(event.event); // e.g., 'update'
  console.log(event.data);  // The message payload
}

API Reference

stream(url: string, options?: StreamOptions)

Returns an AsyncGenerator<string | Uint8Array>.

Options:

  • headers: HeadersInit - Custom headers.
  • retries: number (default: 3) - Max retry attempts on failure.
  • signal: AbortSignal - To cancel the request.
  • decode: boolean (default: true) - If true, yields strings. If false, yields Uint8Array.

streamSSE(url: string, options?: SSEOptions)

Returns an AsyncGenerator<SSEEvent>.

Options:

  • headers: HeadersInit
  • retries: number (default: 3)
  • signal: AbortSignal

SSEEvent Interface:

interface SSEEvent {
  id: string | null;
  event: string | null;
  data: string;
  retry?: number;
}

License

MIT