nestjs-throttler-storage-mongo
TypeScript icon, indicating that this package has built-in type declarations

1.0.1-alpha • Public • Published

Mongo storage provider for the @nestjs/throttler package.

npm version npm download

Package License Coverage

MongoDB Storage Provider for @nestjs/throttler

This package provides a MongoDB TTL (Time-to-Live) storage provider for the @nestjs/throttler package . It allows you to store rate limiter data in a MongoDB collection with automatic expiration of entries using TTL indexes.

Installation Install the package via npm:

npm install nestjs-throttler-storage-mongo

Yarn

yarn add nestjs-throttler-storage-mongo

Usage

To start using NestJS MongoDB Storage Provider, you need to import the ThrottlerStorageMongoService into your application module and configure it with your Mongo connection url and MongoClientOptions.

import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerStorageMongoService } from 'nestjs-throttler-storage-mongo';

@Module({
imports: [
ThrottlerModule.forRoot({
ttl: 60,
limit: 5,

      // Below are possible options on how to configure the storage service.

      // connection url
      storage: new ThrottlerStorageMongoService('mongodb://'),

      // MongoDB connection string with connection options
      storage: new ThrottlerStorageMongoService('mongodb://',{
        useNewUrlParser: true,
        useUnifiedTopology: true,
        // Other connection options
        }
      ),
    }),

],
})
export class AppModule {}

Inject another config module and service:

import { ThrottlerModule } from '@nestjs/throttler';
import { ThrottlerStorageMongoService } from 'nestjs-throttler-storage-mongo';

@Module({
  imports: [
    ThrottlerModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => ({
        ttl: config.get('THROTTLE_TTL'),
        limit: config.get('THROTTLE_LIMIT'),
        storage: new ThrottlerStorageMongoService('mongodb://'),
      }),
    }),
  ],
})
export class AppModule {}

Issues

Bugs and features related to the mongo implementation are welcome in this repository.

License

NestJS Throttler Mongo Storage is licensed under the MIT license.

Versions

Current Tags

Version History

Package Sidebar

Install

npm i nestjs-throttler-storage-mongo

Weekly Downloads

16

Version

1.0.1-alpha

License

MIT

Unpacked Size

104 kB

Total Files

19

Last publish

Collaborators

  • ganesha2552