https://github.com/clarketm/express-sse-example
Real-time Express streaming API leveraging Server Sent Events (SSE)
https://github.com/clarketm/express-sse-example
express server-sent-events sse streaming-api
Last synced: 6 months ago
JSON representation
Real-time Express streaming API leveraging Server Sent Events (SSE)
- Host: GitHub
- URL: https://github.com/clarketm/express-sse-example
- Owner: clarketm
- Created: 2018-09-12T06:57:10.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-12T07:28:07.000Z (about 7 years ago)
- Last Synced: 2025-03-28T00:44:16.607Z (7 months ago)
- Topics: express, server-sent-events, sse, streaming-api
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# express-sse-example
Real-time Express streaming API leveraging Server Sent Events (SSE)### Example
#### Start
```bash
$ npm start
```#### Subscribe (server-side)
```bash
# GET /eventstream
$ curl -XGET "http://localhost:3000/eventstream"
```#### Subscribe (client-side)
```js
const es = new EventSource("http://localhost:3000/eventstream");
es.addEventListener("message", event => console.log(JSON.parse(event.data)));
```#### Publish a "message" event
```bash
# POST /message
$ curl -XPOST "http://localhost:3000/message" -d "some message"
```#### All subscribers will receive the event payload
```json
{
"message": "some message",
"timestamp": "2018-09-12T07:25:45.403Z"
}
```