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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@neabyte/sse-client

v0.1.0

Published

Server-Sent Events (SSE) client for Node.js and browsers with automatic reconnection

Readme

SSE Client License: MIT Bundle Size Node.js CI

Server-Sent Events (SSE) client for Node.js and browsers with automatic reconnection.

📦 Installation

NPM

npm install @neabyte/sse-client

CDN (Browser)

<script type="module">
  import sseClient from 'https://cdn.jsdelivr.net/npm/@neabyte/sse-client/+esm'

  const client = sseClient('https://api.example.com/events', (message) => {
    console.log('SSE Response:', message)
  })
</script>

🚀 Quick Start

Basic Usage

// ESM
import sseClient from '@neabyte/sse-client'

 // CommonJS
const sseClient = require('@neabyte/sse-client')

// Simple connection with message callback
const client = sseClient('https://api.example.com/events', (message) => {
  console.log('SSE Response:', message)
})

Advanced Usage

import sseClient, { type SSEConfig, SSEClient } from '@neabyte/sse-client'

// Configuration with custom settings
const config: SSEConfig = {
  headers: {
    'Authorization': 'Bearer your-token',
    'X-Custom-Header': 'value'
  },
  retryInterval: 5000,    // Retry every 5 seconds (default: 3000)
  retryAttempts: 10,      // Try up to 10 times (default: 3)
  autoReconnect: true,    // Enable auto-reconnection (default: true)
  timeout: 30000          // 30 second connection timeout (default: 30000)
}

// Create client with configuration
const client: SSEClient = sseClient('https://api.example.com/events', (message: unknown) => {
  console.log('SSE Response', message)
}, config)

// Listen for connection status changes
client.on('callback', (data) => {
  console.log('SSE Callback:', data)
})

📖 API Reference

sseClient

sseClient(url, callback, config?)
  • url <string>: The SSE endpoint URL to connect to.
  • callback <function>: Function to handle incoming messages.
    • message <SSEMessage>: The received SSE message object.
  • config <SSEConfig>: (Optional) Configuration options for the client.
    • headers <Record<string, string>>: (Optional) Custom headers to send with the request.
    • retryInterval <number>: (Optional) Retry interval in milliseconds. Defaults to 3000.
    • retryAttempts <number>: (Optional) Maximum number of retry attempts. Defaults to 3.
    • autoReconnect <boolean>: (Optional) Enable automatic reconnection. Defaults to true.
    • timeout <number>: (Optional) Connection timeout in milliseconds. Defaults to 30000.
  • Returns: SSEClient
  • Description: Factory function that creates and connects an SSE client with automatic reconnection.

Methods

connect

client.connect()
  • Returns: Promise<void>
  • Description: Establishes connection to the SSE endpoint with retry logic and error handling.

disconnect

client.disconnect()
  • Returns: void
  • Description: Disconnects from the SSE endpoint and cleans up resources.

Events

callback

client.on('callback', (status) => {})
  • status <object>: Connection status information.
    • name <ConnectionStatus>: Current connection status. Possible values:
      • 'connecting' - Initial connection attempt
      • 'connected' - Successfully connected and streaming
      • 'disconnected' - Connection closed (normal or error)
      • 'reconnecting' - Attempting to reconnect after failure
      • 'error' - Connection failed with error
    • message <string | null>: Optional status message.
  • Description: Emitted when connection status changes.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.