Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ssestream

EventSource34.7kMIT1.1.0TypeScript support: included

Send Server-Sent Events with a stream

readme

SseStream

A zero-dependency 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')

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).

changelog

CHANGE LOG

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.


Unreleased

Added

N/A

Changed

N/A

Deprecated

N/A

Removed

N/A

Fixed

N/A

1.1.0 - 2020-03-17

Added

  • Add SseStream#writeMessage as a typesafe alias to SseStream#write

Changed

  • Ported code to TypeScript

1.0.1 - 2017-12-28

Fixed

  • The retry field is set properly

1.0.0 - 2017-11-22

Added

  • First stable release!