Socket
Socket
Sign inDemoInstall

better-sse

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-sse

Dead simple, dependency-less, spec-compliant server-side events implementation for Node, written in TypeScript.


Version published
Weekly downloads
4K
increased by4.38%
Maintainers
1
Weekly downloads
 
Created
Source

Better SSE

A dead simple, dependency-less, spec-compliant server-side events implementation for Node, written in TypeScript.

This package aims to be the easiest to use, most compliant and most streamlined solution to server-side events with Node that is framework agnostic and feature rich.

Please consider starring the project on GitHub ⭐.

Why use Server-sent Events?

Server-sent events (SSE) is a standardised protocol that allows web-servers to push data to clients without the need for alternative mechanisms such as pinging or long-polling.

Using SSE can allow for significant savings in bandwidth and battery life on portable devices, and will work with your existing infrastructure as it operates directly over the HTTP protocol without the need for the connection upgrade that WebSockets require.

Compared to WebSockets it has comparable performance and bandwidth usage, especially over HTTP/2, and natively includes event ID generation and automatic reconnection when clients are disconnected.

Highlights

See a comparison with other Node SSE libraries in the documentation.

Installation

# npm
npm install better-sse

# Yarn
yarn add better-sse

# pnpm
pnpm add better-sse

Better SSE ships with types built in. No need to install from @types for TypeScript users!

Basic Usage

The following example shows usage with Express, but Better SSE works with any web-server framework (that uses the underlying Node HTTP module).

See the Recipes section of the documentation for use with other frameworks and libraries.

// Server
import {createSession} from "better-sse";

app.get("/sse", async (req, res) => {
	const session = await createSession(req, res);

	session.push("Hello world!");
});
// Client
const sse = new EventSource("/sse");

sse.addEventListener("message", ({data}) => {
	console.log(data);
});

Check the API documentation and live examples for information on getting more fine-tuned control over your data such as managing event IDs, data serialization, streams, dispatch controls and more!

Documentation

API documentation, getting started guides and usage with other frameworks is available on GitHub.

Contributing

This library is always open to contributions, whether it be code, bug reports, documentation or anything else.

Please submit suggestions, bugs and issues to the GitHub issues page.

For code or documentation changes, submit a pull request on GitHub.

Local Development

Install Node:

curl -L https://git.io/n-install | bash
n auto

Install pnpm:

npm i -g pnpm

Install dependencies:

pnpm i

Run tests:

pnpm t

License

This project is licensed under the MIT license.

Keywords

FAQs

Package last updated on 28 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc