@saverious/rate-limiter

1.0.2 • Public • Published

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.

Package Sidebar

Install

npm i @saverious/rate-limiter

Weekly Downloads

4

Version

1.0.2

License

ISC

Unpacked Size

5.04 kB

Total Files

5

Last publish

Collaborators

  • saverious