ssestream2
v1.0.0
Published
Serverside event stream
Downloads
6
Maintainers
Readme
SseStream
A node stream for writing Server-Sent Events
Note I merged together:
- https://github.com/EventSource/node-ssestream/blob/master/README.md
- https://gist.github.com/gitawego/8ef33ec7d895498f2eedd95eafa835bb
- https://github.com/EventSource/node-ssestream/pull/2
Installation
npm install ssestream2
Or:
yarn add ssestream2
Usage
In a (req, res)
handler for a request
event, Express #get route or similar:
const SseStream = require('ssestream2')
function (req, res) {
const headers = {'CUSTOM-HEADER': 'FOO'}
const sse = new SseStream(req, headers)
sse.pipe(res)
const message = {
data: 'hello\nworld',
}
sse.write(message)
}
Properties on message
:
data
(String or object, which gets turned into JSON)event
id
retry
comment