Skip to content

billylaing/expreSSE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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();
}

About

Simple Express Middleware SSE Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published