
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
@types/express-rate-limit
Advanced tools
Stub TypeScript definitions entry for express-rate-limit, which provides its own types definitions
@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.
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);
express-slow-down is a middleware for Express that slows down responses rather than blocking them when a user is making too many requests. This can be useful for deterring abuse while still allowing legitimate users to access the service, albeit at a slower rate.
rate-limiter-flexible is a more flexible and powerful rate limiting library that supports various backends like Redis, MongoDB, and in-memory storage. It provides more advanced features compared to express-rate-limit, such as different rate limiting strategies and more granular control over rate limiting rules.
This is a stub types definition for @types/express-rate-limit (https://github.com/nfriedly/express-rate-limit).
express-rate-limit provides its own type definitions, so you don't need @types/express-rate-limit installed!
FAQs
Stub TypeScript definitions entry for express-rate-limit, which provides its own types definitions
The npm package @types/express-rate-limit receives a total of 150,893 weekly downloads. As such, @types/express-rate-limit popularity was classified as popular.
We found that @types/express-rate-limit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.