Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

express-sse

dpskvn27.1kMIT1.0.0TypeScript support: included

An Express middleware for Server-Sent Events (EventSource)

express, sse, server-sent, events, eventsource, middleware, stream

readme

express-sse

npm version

NPM

An Express middleware for quick'n'easy server-sent events.

About

express-sse is meant to keep things simple. You need to send server-sent events without too many complications and fallbacks? This is the library to do so.

Installation:

npm install --save express-sse

or

yarn add express-sse

Usage example:

Options:

You can pass an optional options object to the constructor. Currently it only supports changing the way initial data is treated. If you set isSerialized to false, the initial data is sent as a single event. The default value is true.

var sse = new SSE(["array", "containing", "initial", "content", "(optional)"], { isSerialized: false, initialEvent: 'optional initial event name' });

Server:

var SSE = require('express-sse');
var sse = new SSE(["array", "containing", "initial", "content", "(optional)"]);

...

app.get('/stream', sse.init);

...

sse.send(content);
sse.send(content, eventName);
sse.send(content, eventName, customID);
sse.updateInit(["array", "containing", "new", "content"]);
sse.serialize(["array", "to", "be", "sent", "as", "serialized", "events"]);

Client:

var es = new EventSource('/stream');

es.onmessage = function (event) {
  ...
};

es.addEventListener(eventName, function (event) {
  ...
});

changelog

Changelog

1.0.0

Add ESM support and TypeScript definitions

0.6.0

Fixed:

  • use res.flush() only on old versions of Node
  • moved tests to jest

0.5.3

Fixed:

  • compression support

0.5.2

Fixed:

  • node 4 and 5 support

0.5.1

Added

  • HTTP/2 does not read connection headers

Fixed:

  • security update in yarn.lock

0.5.0

Added:

  • compression support with isCompressed option

Fixed:

  • TimeoutOverflowWarning

0.4.1

Added:

  • dropInit method
  • more tests

Fixed:

  • event listener handling
  • don't send an empty array on initial event for isSerialized = false

0.4.0

Added:

  • serialize method
  • initial options
  • basic test suites

Fixed:

  • event listener memory leak

0.3.2

Fixed:

  • node v4 compatibility

0.3.1

Fixed:

  • internal fixes

0.3.0

Added:

  • named events
  • custom IDs

0.2.1

Fixed:

  • crashes on node v0.12

0.2.0

Added:

  • initial content
  • initial content updating

0.1.0

  • initial release