Registry / security / nest-ratelimiter

nest-ratelimiter

JSON →
library0.4.0jsnpmunverified

A distributed, consistent rate limiter for NestJS backed by Redis, designed for high-traffic applications. Version 0.4.0 uses Lua scripts for atomic operations with configurable limits (max, duration) via decorators or guards. Integrates with `nestjs-redis` or `ioredis`. Stable, actively maintained with support for NestJS 8–11. Compared to `nestjs-rate-limiter`, this package offers Lua-based atomicity and flexible Redis integration.

npm install nest-ratelimiter
INSTALL
IMPORT
SIG · NEST-RATELIMITER
N
nest-ratelimiter
securityjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RateLimiterModule
import { RateLimiterModule } from 'nest-ratelimiter';
import RateLimiterModule from 'nest-ratelimiter';
Named export, not default.
RateLimit
import { RateLimit } from 'nest-ratelimiter';
const { RateLimit } = require('nest-ratelimiter');
ESM-only since v0.4.0 (Node >=18).
RateLimiterGuard
import { RateLimiterGuard } from 'nest-ratelimiter';
import { RateLimiterGuard } from 'nest-ratelimiter/guards';
All exports are from the main package.

Shows module registration with Redis config and rate limiting on a route with 10 requests per minute limit.

// app.module.ts import { Module } from '@nestjs/common'; import { RateLimiterModule } from 'nest-ratelimiter'; @Module({ imports: [ RateLimiterModule.register({ for: 'Microservice', // or 'Web' redis: { host: process.env.REDIS_HOST || 'localhost', port: Number(process.env.REDIS_PORT) || 6379, }, }), ], }) export class AppModule {} // controller.ts import { Controller, Get, UseGuards } from '@nestjs/common'; import { RateLimit, RateLimiterGuard } from 'nest-ratelimiter'; @Controller() @UseGuards(RateLimiterGuard) export class AppController { @Get() @RateLimit({ max: 10, duration: 60000 }) // 10 requests per minute getHello(): string { return 'Hello!'; } }
Debug
Known issues
breakingESM-only import; requires Node >=18
fix
Use `import` syntax and Node >=18.
affects: >=0.4.0
gotchaRate limit is enforced per route, not globally by default. Use guard globally to apply to all routes.
fix
Apply `@UseGuards(RateLimiterGuard)` at the controller or module level.
affects: *
deprecatedThe `for: 'Microservice'` option uses Redis List, `'Web'` uses Redis Sorted Set. Different implementations.
fix
Check documentation; no breaking change but understand the difference.
affects: <0.4.0
gotchaMust have Redis running; no fallback. If Redis is down, rate limiting fails.
fix
Ensure Redis is available or handle connection errors.
affects: *
breakingMinimum Node.js version is 18.0.0 starting from v0.4.0.
fix
Upgrade Node to 18+.
affects: >=0.4.0
Errors
Common errors & fixes
Cannot find module 'nest-ratelimiter' or its corresponding type declarations.
Missing package installation or wrong import path.
fix
Run `npm install nest-ratelimiter` and ensure tsconfig.json includes 'node_modules' or 'esModuleInterop'.
RateLimiterGuard requires an HTTP context. Are you in a web context?
Using RateLimiterGuard in a non-HTTP context (e.g., Microservice) without proper decorator.
fix
Use `@RateLimit()` decorator only, or ensure the guard is used in an HTTP context.
ERR wrong number of arguments for 'eval' command
Redis Lua script argument mismatch (rare, possibly due to version incompatibility).
fix
Update ratelimiter and redis packages to latest compatible versions.
TypeError: Cannot read properties of undefined (reading 'set')
RateLimiterModule.register() not called or missing 'redis' config.
fix
Ensure module is imported with `.register({for: 'Web', redis: {...}})`.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
msrequiredhuman-readable time durations
ratelimiterrequiredcore rate limiting logic (generic Redis-based)
@nestjs/corerequiredNestJS framework core
@nestjs/commonrequiredNestJS common utilities
@types/ratelimiteroptionalTypeScript type definitions for ratelimiter
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
nest-ratelimiter — npm install nest-ratelimiter · libregistry