@routup/rate-limit-redis
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

@routup/rate-limit-redis

npm version main codecov Known Vulnerabilities Conventional Commits

This is a redis adapter for the rate-limit plugin.

Table of Contents

Installation

npm install @routup/rate-limit-redis --save

Documentation

To read the docs, visit https://routup.net

Usage

import { createServer } from 'node:http';
import {
    createNodeDispatcher,
    Router
} from 'routup';
import { rateLimit } from '@routup/rate-limit';
import { RedisStore } from '@routup/rate-limit-redis';

const router = new Router();

// Apply the rate limiting middleware to API calls only
router.use('/api', rateLimit({
    // 15 minutes
    windowMs: 15 * 60 * 1000,

    // Limit each IP to 100 requests
    // per `window` (here, per 15 minutes)
    max: 100,

    // connection string or ioredis instance 
    // can be passed optional as argument 
    store: new RedisStore(),
}));

const server = createServer(createNodeDispatcher(router));
server.listen(3000);

License

Made with 💚

Published under MIT License.

This library is heavily inspired by express-rate-limit-redis.

Package Sidebar

Install

npm i @routup/rate-limit-redis

Weekly Downloads

0

Version

3.0.0

License

MIT

Unpacked Size

21.4 kB

Total Files

11

Last publish

Collaborators

  • tada5hi