pull-sse

Server-sent events magic for pull-streams

npm install pull-sse
7 downloads in the last week
28 downloads in the last month

pull-sse

Use pull-streams to make server sent events wonderful.

NPM

Build Status

browser support

Usage

The pull-sse module is designed to be used as both pull sink and source but at this stage, only the sink has been implemented.

Sink usage:

var http = require('http');
var server = http.createServer();
var pull = require('pull-stream');
var sse = require('pull-sse');

server.on('request', function(req, res) {
  if (req.url === '/values') {
    return pull(
      pull.values(['a', 'b', 'c']),
      sse(res)
    );
  }
});

server.listen(3000);

This could then be consumed in the browser, very simply:

var source = new EventSource('/values');

source.addEventListener('message', function(evt) {
  console.log(evt.data);
});

For more examples, I'd recommend trawling through the examples.

npm loves you