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

@jadsonlucena/sse

v1.0.0

Published

A complete and minimalist Server-Sent Events (SSE) for server Node.js ≥ v14.x

Readme

SSE-Node

A complete and minimalist Server-Sent Events (SSE) for server Node.js ≥ v14.x

Which is?

It is a system real-time, unidirectional (from server to client) and persistent. It is a connection similar to the websocket in terms of handling received events, more with the possibility of having customized events.

Interfaces

// Constructor
SSE(
    server: Object, // HTTP(s) Server Object
    {
        allowOrigin?: String | Array<String> | Null, // Allowed domains (Default: Null)
        limitByIP?: UInteger, // IP access limit (Default: 256)
        path?: String, // Path using in route (Default: /sse)
        withCredentials?: Boolean // Tells whether the client can use CORSS credentials or not (Default: False)
    }?
): Class
// Getters
allowOrigin(): String | Array<String> | Null

clients(): Array<String> // List of connected user ID's

limitByIP(): UInteger

path(): String

withCredentials(): Boolean
// Setters
allowOrigin(input?: String | Array<String> | Null): Void // (Default: Null)

limitByIP(input?: UInteger): Void // (Default: 256)

path(input?: String): Void // (Default: /sse)

withCredentials(input?: Boolean): Void // (Default: False)
// Methods
close(clientId: String): Boolean | Null

send(
    clientId: String,
    data: String, // Message content
    {
        encoding?: String, // [utf8 | ascii | base64 | hex | binary | utf16le | ucs2] (Default: utf8)
        event?: String, // If specified, an event will be dispatched to the browser on the listener instantiated with the same name.
        id?: String, // Defines the last event ID value of the EventSource object.
        retry?: Integer // This must be an integer, specifying the reconnection time in milliseconds
    }?
): Boolean | Null

How to use

// Front-end
var source = new EventSource('/sse');

source.onerror = e => console.log('Error', e);

source.onopen = e => {

    console.log('Open', e);

    source.addEventListener('custom', e => console.log('Custon', e));
    
    source.onmessage = e => console.log('Message', e);

};
// Back-end
const SSE = require('@jadsonlucena/sse'); // npm i @jadsonlucena/sse

let sse = new SSE(server);

sse.on('close', (clientId, e) => console.log('Close', clientId, e));

sse.on('error', (clientId, e) => console.log('Error', clientId, e));

sse.on('open', (clientId, lastEventId) => {
    
    console.log('Open', clientId, lastEventId);

    // Custom events
    sse.send(clientId, 'Hello World', {
        event: 'custom'
    });

    // Single Client
    sse.send(clientId, 'Hello World');

    // Broadcast
    sse.clients.forEach(clientId => sse.send(clientId, 'Hello World'));

});

By default the lib constructor on the back-end expects the /sse path to be inserted into the front-end constructor. If you prefer another path on the front-end, it must be specified in the back-end constructor.

Custom events must be instantiated on the front-end and referenced on the back-end.

References

Server-sent events
Using server-sent events