@saverious/rate-limiter
v1.0.2
Published
An in-memory rate limiter for http request throttling
Downloads
218
Maintainers
Readme
NodeRateLimiter
@saverious/rate-limiter implements rate limiting based on ip addresses, available for express.js servers.
@saverious/rate-limiter uses in-memory storage to keep track of client requests, therefore is suitable only for small-scale servers.
Install
npm i @saverious/rate-limiter
Usage
import limiter from '@saverious/rate-limiter';
import express from 'express';
const app = express();
// use default rate-limiter settings
// app.use(limiter());
// use custom rate-limiter settings
app.use(limiter({
windowMS: 20 * 1000,
limit: 5
}));
// test endpoint
app.get('/', function(req, res) {
res.status(200).json({ name: 'john doe' });
});
app.listen(80, () => {
console.log('listening on port 80');
});
Note
This package uses ES module syntax. For codebases using CommonJS module, use dynamic imports.