Skip to content

tillhub/node-ssestream

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SseStream

A node stream for writing Server-Sent Events

Installation

npm install ssestream

Or:

yarn add ssestream

Usage

In a (req, res) handler for a request event, Express #get route or similar:

const SseStream = require('ssestream')
const customHeaders = {'Cache-Control': 'no-cache, no-transform'} // optional

function (req, res) {
  const sse = new SseStream(req)
  sse.pipe(res, undefined, customHeaders)
  
  const message = {
    data: 'hello\nworld',
  }
  sse.write(message)
}

Properties on message:

  • data (String or object, which gets turned into JSON)
  • event
  • id
  • retry
  • comment

About

Send Server-Sent Events with a stream

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%