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

cov-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cov-rate-limit

rate-limiting middleware for Express and Koa

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-60%
Maintainers
1
Weekly downloads
 
Created
Source

Cov Rate Limit

A lightweight Rate limiter middleware for Express and Koa. Use to limit repeated requests to public APIs.

Install

$ npm install --save cov-rate-limit

Example

Koa

const Koa = require('koa')
const RateLimit = require('cov-rate-limit')

const app = new Koa()

const rateLimiter = RateLimit({
    type: 'koa',
    max: 100,
    duration: 1000 * 60 * 10,
    key (ctx) {
        return ctx.ip
    }
})

app.use(rateLimiter)

Express

RateLimit with redis

const express = require('express')
const RateLimit = require('cov-rate-limit')

const Redis = require('redis')
const redis = Redis.createClient()

const rateLimiter = RateLimit({
    type: 'express',
    max: 100,
    duration: 1000 * 60 * 10, // 10 min
    key (req) {
        return req.ip
    },
    cache: redis
})

const app = express()

app.set('trust proxy', 1)

const data = {
    data: {
        message: '11111111'
    },
    list: Array.from({ length: 10000 }).map((t, i) => i)
}

app.get('/api1', rateLimiter, (req, res) => {
    res.send(data)
})

Options

{
    type: 'koa' // 'express'
    CacheKey: 'C0V_RATE:',
    key (req) {
        return req.ip
    },
    max: 500, // max requests within duration [500]
    duration: 1000 * 60 * 15, // of limit in milliseconds [15 * 60 * 1000]
    setHeader: true,
    cache: redis // redis client [in memory cache]
    endSender (req, res) {},
    // endSender (ctx, next) {}
}

License

MIT © Awe

inspiration by express-rate-limit

Keywords

FAQs

Package last updated on 28 Apr 2017

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