Skip to content

jeffcordova/express-sse-example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-sse-example

Real-time Express streaming API leveraging Server Sent Events (SSE)

Example

Start

$ npm start

Subscribe (server-side)

# GET /eventstream
$ curl -XGET "http://localhost:3000/eventstream"

Subscribe (client-side)

const es = new EventSource("http://localhost:3000/eventstream");
es.addEventListener("message", event => console.log(JSON.parse(event.data)));

Publish a "message" event

# POST /message
$ curl -XPOST "http://localhost:3000/message" -d "some message"

All subscribers will receive the event payload

{
  "message": "some message", 
  "timestamp": "2018-09-12T07:25:45.403Z"
}

About

Real-time Express streaming API leveraging Server Sent Events (SSE)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%