You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@types/express-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/express-rate-limit

Stub TypeScript definitions entry for express-rate-limit, which provides its own types definitions

6.0.0
npmnpm
Version published
Weekly downloads
178K
-2.35%
Maintainers
1
Weekly downloads
 
Created

What is @types/express-rate-limit?

@types/express-rate-limit provides TypeScript type definitions for the express-rate-limit middleware, which is used to limit repeated requests to public APIs and/or endpoints in an Express application.

What are @types/express-rate-limit's main functionalities?

Basic Rate Limiting

This feature allows you to set up basic rate limiting for your Express application. The code sample demonstrates how to limit each IP to 100 requests per 15 minutes.

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100 // limit each IP to 100 requests per windowMs
});
app.use(limiter);

Custom Response

This feature allows you to customize the response message when the rate limit is exceeded. The code sample shows how to send a custom message when the limit is reached.

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100, // limit each IP to 100 requests per windowMs
  message: 'Too many requests from this IP, please try again after 15 minutes'
});
app.use(limiter);

Custom Key Generator

This feature allows you to define a custom key generator function. The code sample demonstrates how to use the request IP address as the key for rate limiting.

const rateLimit = require('express-rate-limit');
const limiter = rateLimit({
  windowMs: 15 * 60 * 1000, // 15 minutes
  max: 100, // limit each IP to 100 requests per windowMs
  keyGenerator: (req, res) => req.ip // use the request IP address as the key
});
app.use(limiter);

Other packages similar to @types/express-rate-limit

FAQs

Package last updated on 06 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts