A Server-Sent Events component
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
History.md
Makefile
Readme.md
component.json
example.html
example.js
index.js

Readme.md

sse

A nice Server-Sent Events api

Example

With a SSE endpoint that responds like this:

$ curl http://localhost/updates
data: foo

data: bar

data: quit

And a script that subscribes to its updates:

var sse = require('sse');

var unbind = sse('/updates', function(data){
  if (data == 'quit') unbind();
  console.log(data);
});

The console output will be:

foo
bar
quit

Installation

Install with component(1):

$ component install segmentio/sse

API

sse(url, fn)

Subscribe fn to events on url. Returns an unbind function.

License

MIT