expresse

1.0.2 • Public • Published

Simple SSE Server

Simple middleware that will leave the HTTP connection and use it for SSE communication.

NPM Version NPM Monthly NPM Downloads

Below is an example of setting up the server on the /events route.

var SSEServer = require('expresse');
var sse = new SSEServer('events');
 
app.get('/events', function(req, res) {
    sse.connect(req, res);
    sse.broadcast('greeting', {message: 'hello world'});
});

Client code is simple too!

var events = new EventSource('http://localhost:4000/events');
 
events.addEventListener('greeting', function(event) {
    var data = JSON.parse(event.data);
    console.log('greeting: '+ data);
});
 
events.onopen = function(e) {
    //called when socket is listenning
}
 
events.onerror = function(e) {
    events.close();
}

Package Sidebar

Install

npm i expresse

Weekly Downloads

76

Version

1.0.2

License

MIT

Last publish

Collaborators

  • billylaing