npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-device-rate-limit

v1.0.4

Published

![npm version](https://img.shields.io/npm/v/express-device-rate-limit) ![dependency status](https://img.shields.io/librariesio/release/npm/express-device-rate-limit) ![gitHub top language](https://img.shields.io/github/languages/top/aspiesoft/express-devi

Downloads

10

Readme

Express Device Rate Limit

npm version dependency status gitHub top language npm license

npm weekly downloads npm monthly downloads

donation link

Rate limiting that can be stricter on cirtain devices or geo locations.

Installation

npm install express-device-rate-limit

Setup


const deviceRateLimit = require('express-device-rate-limit');

const express = require('express');
const app = express();

const rateLimit = deviceRateLimit({/* options */});


// auto setup
rateLimit.all(app);


// manual setup

// body parser pre config
app.use(rateLimit.bodyParserUrlEncoded());
app.use(rateLimit.bodyParserJSON());
// or access the body-parser module directly
app.use(rateLimit.bodyParser.urlencoded({extended: true}))
app.use(rateLimit.bodyParser.json({type: ['json', 'application/csp-report'], limit: '1mb'}))

// device.capture function
app.use(rateLimit.deviceCapture());
// or access the express-device module directly
app.use(rateLimit.device.capture());

app.use(rateLimit.rateLimit());

Usage


//node: these are the default values for these options
const rateLimit = deviceRateLimit({

  // the number of requests that can be made by a user within a given time
  // this is multiplied by the value of the defEffect option
  limit: 100,

  // the amount of time before reseting the recording of a users request rate
  // s: seconds, m: minutes, h: hours, D: days, M: months, Y: years
  time: '1m',

  // the amount of time to kick a user who goes above the rate limit
  kickTime: '1h',

  // the default score to increase a user request rate by
  defEffect: 5,

  // the minimum score to increase a user request rate by
  minEffect: 1,

  // the maximum score to increase a user request rate by
  maxEffect: this.limit * this.defEffect / 20,

  // how strict should a score increase be
  // the amount a score is increased by will be multiplied by this number
  strict: 1,

  // how passive should a score decrease be
  // the amount a score is decreased by will be multiplied by this number
  passive: 1,


  // optional: handle a rate limit error in any way you want
  err: function(req, res, next){
    // by default this status and message is sent if a users request rate goes past the limit
    res.status(429).send('<h1>Error 429</h1><h2>Too Many Requests</h2>').end();
  },


  // optional: geo location options
  // you can increase the effect (rate score) of a user based on location
  geo: {

    // how strict should a score increase be
    // the amount a score is increased by will be multiplied by this number
    //note: if this number is negative, the score will be decreased
    // a decreased score allows you to be stricter on a specific location instead
    strict: 1,

    // the below options are disabled and ignored by default
    //note: each option is added up
    // specifying a country and region will increase the score twice if neither apply

    country: ['US'], // +4
    region: ['NY'], // +3
    city: ['MyCityName'], // +2
    timezone: ['America/New_York'], // +2
    range: [12345, 67890], // +1
    area: 1, // +0.5
    metro: 123, // +0.5

    //note: if the geoIP module returns null, their score will be increased by +2
  },
});