Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 568 Bytes

readme.md

File metadata and controls

30 lines (21 loc) · 568 Bytes

RT Limit

A simple IP address based rate limiting module written in Typescript with zero dependencies.

See how it's implemented at my blog post.

Installation

npm i rt-limit

Usage

import Ratelimit from 'rt-limit';
import express from 'express';

const ratelimit = new Ratelimit(60, 60 * 1000);
const app = express();

app.use((req, res, next) => {
  if (ratelimit.consume(req.ip, 1)) {
    next();
    return;
  }

  res.status(429).end();
});