New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rate-limit-mongo

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rate-limit-mongo

Provides a Mongo store for the express-rate-limit middleware.

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by12.37%
Maintainers
3
Weekly downloads
 
Created
Source

Rate Limit Mongo

MongoDB store for the express-rate-limit middleware.

Npm version Build Status Coverage Status Known Vulnerabilities

Install

$ npm install --save rate-limit-mongo

Usage

var RateLimit = require('express-rate-limit');
var MongoStore = require('rate-limit-mongo');

var limiter = new RateLimit({
  store: new MongoStore({
    // see Configuration
  }),
  max: 100,
  windowMs: 15 * 60 * 1000
});

//  apply to all requests
app.use(limiter);

Configuration

  • uri: string -- uri for connecting to mongodb, mongodb://127.0.0.1:27017/test_db for example. Required if collection hasn't been set.

  • collectionName: string -- name of collection for storing records. Defaults to expressRateRecords

  • user: string -- username for authentication in mongodb

  • password: string -- password for authentication in mongodb

  • authSource: string -- db name against which authenticate use. If not set db name from uri will be taken.

  • collection: object -- mongodb collection instance. Required if uri hasn't been set.

  • expireTimeMs: integer -- time period, in milliseconds, after which record will be reseted (deleted). Defaults to 60 * 1000. Note that current implementation uses on mongodb ttl indexes - background task that removes expired documents runs every 60 seconds. As a result, documents may remain in a collection during the period between the expiration of the document and the running of the background task. See mongodb ttl indexes doc for more information.

  • resetExpireDateOnChange: boolean -- indicates whether expireDate should be reseted when changed or not. Defaults to false.

  • errorHandler: function -- function that will be called if error happened during incr, decrement or resetKey methods. Defaults to _.noop.

  • createTtlIndex: boolean -- defines whether create ttl index ( on expirationDate field with expireAfterSeconds: 0) on collection or not. Could be useful in situations when you don't want to create index from the app e.g. due to restricted db permissions (see #15 for details). Defaults to true.

Methods

MongoStore class provides public methods (incr, decrement, resetKey) required by express-rate-limit.

In addition following methods provided:

  • getClient(callback) - if collection was not passed to the constructor then that method will pass (as second argument) initiated instace of MongoClient to the callback, otherwise null will be passed. Thus this method provides control over connection initiated by the library to the end user. This method is promisified (when util.promisify is presented (node.js >= 8)).

Keywords

FAQs

Package last updated on 22 May 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc