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!';
}
}
Errors
Common errors & fixes
Cannot find module 'nest-ratelimiter' or its corresponding type declarations.
Missing package installation or wrong import path.
fixRun `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.
fixUse `@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).
fixUpdate ratelimiter and redis packages to latest compatible versions.
TypeError: Cannot read properties of undefined (reading 'set')
RateLimiterModule.register() not called or missing 'redis' config.
fixEnsure module is imported with `.register({for: 'Web', redis: {...}})`. 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