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

simple-sse

v0.0.3

Published

A really simple library to work with Server-Sent Events in Node.js

Readme

Simple Server-Sent Events

A really simple library to work with Server-Sent Events in Node.js

> Mozilla Reference

Installation

You can use npm module, or just copy lib/index.js into your own package!

npm install --save simple-sse

Don't forget to require it ! var sse = require("simple-sse");

To work, this module requires a http server. You can use express.

Usage

This library is for a global use in your application (e.g. you don't have to call new instances). It's designed to work with rooms for several jobs in your application.

Here is the API :

####sse.add(req, res)

Register a client using it's own http req and res object. You can add this instruction in a classic route. For example :

app.get('/realtime', function(req, res) {
	sse.add(req, res);
});

Returns a SSE client.

####sse.setRetry(client, retry)

Send retry interval to a specified client. If the browser lose connection to the server, it will wait retry ms before reconnecting.

####sse.join(client, room)

When a client has to join a particular room. A client can join several rooms.

app.get('/room/:roomId', function(req, res) {
	var client = sse.add(req, res);
	sse.join(client, parseInt(req.params.roomId));
});

####sse.leave(client, room)

To leave a room.

####sse.in(client, room)

Returns true if the client is in the room. Room "*" will always return true.

####sse.send(client, [event], data)

Send an event to the client. Data can be multiline or an object, Simple-SSE will parse it correctly.

####sse.broadcast(room, [event], data)

Send an event to each client in "room" room. "room" parameter can be "*".

####sse.remove(client)

Remove a client for Simple-SSE store. It will not close the connection to the client. Used internally when a client closes the connection.

####sse.heartbeat

Heartbeat interval in ms. Default: 20000.

Client-side ?

Here is an example for a javascript client.

var source = new EventSource("/link");
source.addEventListener("eventName", function(e) {
    console.log(e.data);
});
source.onmessage = function(e) {
    //called when data is provided without event name
}
source.onopen = function(e) {
    //called when socket is listenning
}
source.onerror = function(e) {
    source.close();
}

Test

If you have cloned/forked this repository, you can test it with mocha. Just type npm test in simple-sse directory.

Changelog

v0.0.3

  • Now works with node v0.12

v0.0.2

  • Added retry(client, retry) function.
  • Added heartbeat system to avoid connection loss if no data is passed. (not tested for now)

Enjoy !

This is a very simple library, but don't hesitate to fork and send pull requests :)