1. express-sse
An Express middleware for Server-Sent Events (EventSource)
express-sse
Package: express-sse
Created by: dpskvn
Last modified: Fri, 17 Jun 2022 22:40:32 GMT
Version: 0.5.3
License: MIT
Downloads: 13,940
Repository: https://github.com/dpskvn/express-sse

Install

npm install express-sse
yarn add express-sse

express-sse

npm version Build Status Code Climate codecov

NPM

An Express middleware for quick'n'easy server-sent events.

About

express-sse is meant to keep things simple. You need to send server-sent events without too many complications and fallbacks? This is the library to do so.

Installation:

npm install --save express-sse

or

yarn add express-sse

Usage example:

Options:

You can pass an optional options object to the constructor. Currently it only supports changing the way initial data is treated. If you set isSerialized to false, the initial data is sent as a single event. The default value is true.

 var sse = new SSE(["array", "containing", "initial", "content", "(optional)"], { isSerialized: false, initialEvent: 'optional initial event name' });

Server:

 var SSE = require('express-sse');
var sse = new SSE(["array", "containing", "initial", "content", "(optional)"]);

...

app.get('/stream', sse.init);

...

sse.send(content);
sse.send(content, eventName);
sse.send(content, eventName, customID);
sse.updateInit(["array", "containing", "new", "content"]);
sse.serialize(["array", "to", "be", "sent", "as", "serialized", "events"]);

Client:

 var es = new EventSource('/stream');

es.onmessage = function (event) {
  ...
};

es.addEventListener(eventName, function (event) {
  ...
});

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code