2.0.0 • Published 10 months ago

samba-bo-pressure v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

samba-bo-pressure

Pressure based rate limiter

Description

This package exports a pressure based rate limiter that is used within SambaBO, an open-source headless CMS.

Installation

npm install samba-bo-pressure

Usage

Standalone

The pressure monitor is a class that can be used anywhere:

import { PressureMonitor } from 'samba-bo-pressure';

const monitor = new PressureMonitor({
	maxEventLoopUtilization: 0.8,
});

monitor.overloaded; // true | false

Express

The library also exports an express middleware that can be used to throw an Error when the pressure monitor reports overloaded:

import express from 'express';
import { handlePressure } from 'samba-bo-pressure';

const app = express();

app.use(
	handlePressure({
		maxEventLoopUtilization: 0.8,
	}),
);

License

This package is licensed under the MIT License.

2.0.0

10 months ago