express-stream-sse
v1.0.2
Published
Convert NodeJS streams to Server-Sent Events express routes (EventSource)
Downloads
4
Maintainers
Readme
express-stream-sse
Convert NodeJS streams to Server-Sent Events express routes (EventSource)
Install
npm i -S express-stream-sse
Usage
import express from 'express';
import streamToSSE from 'express-stream-sse';
let app = express();
app.get('/events', function(req, res) {
var stream = require('./getSampleStream');
return streamToSSE(res, stream);
});
app.listen(process.env.PORT || 4000);
Then on the client side you can :
var source = new EventSource('/events');
source.onmessage = function(e) {
document.body.innerHTML += e.data + '<br>';
};
Dependencies
Package | Version | Dev --- |:---:|:---: babel-cli | ^6.3.17 | ✔ babel-eslint | * | ✔ babel-preset-es2015 | * | ✔ babel-tape-runner | * | ✔ eslint | * | ✔ eslint-config-airbnb | * | ✔ node-interval-stream | 1.0.0 | ✔ node-readme | ^0.1.8 | ✔ tap-spec | ^4.0.2 | ✔ tape | ^4.0.0 | ✔ zuul | ^3.8.0 | ✔
Author
Julien Bouquillon [email protected] http://github.com/revolunet
License
- MIT : http://opensource.org/licenses/MIT