https://github.com/eventsource/node-ssestream
Send Server-Sent Events with a stream
https://github.com/eventsource/node-ssestream
Last synced: 9 months ago
JSON representation
Send Server-Sent Events with a stream
- Host: GitHub
- URL: https://github.com/eventsource/node-ssestream
- Owner: EventSource
- License: mit
- Created: 2017-09-14T16:32:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-02T22:10:26.000Z (over 2 years ago)
- Last Synced: 2025-10-06T01:59:56.158Z (9 months ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 45
- Watchers: 4
- Forks: 9
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# SseStream
A zero-dependency node stream for writing [Server-Sent Events](https://html.spec.whatwg.org/multipage/server-sent-events.html).
## Installation
```
npm install ssestream
```
Or:
```
yarn add ssestream
```
## Usage
In a `(req, res)` handler for a [`request`](https://nodejs.org/api/http.html#http_event_request) event, Express [#get](https://expressjs.com/en/4x/api.html#app.get.method) route or similar:
```javascript
const SseStream = require('ssestream')
function (req, res) {
const sse = new SseStream(req)
sse.pipe(res)
const message = {
data: 'hello\nworld',
}
sse.write(message)
}
```
Properties on `message`:
* `data` - String or object, which gets turned into JSON
* `event` - (optional) String
* `id` - (optional) String
* `retry` - (optional) number
* `comment` - (optional) String
## TypeScript
The `SseStream#writeMessage(message)` method is a type-safe alias for `SseStream#write(message)`.