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

nogo

v1.0.0

Published

A simple rate limiter intended for human users

Downloads

2

Readme

NoGo

NoGo is a super simple rate limiter intended for human users. Requests exceeding the limit rate earn strikes, and enough strikes can result in being ignored (indefinitely or with cooldown). Configure instances of the rate limiter and provide callbacks for the "no" (rate exceeded) and "go" (request allowed) cases.

Installation

npm install nogo

Creation

Create a rate limiter instance by passing the module a configuration object:

var rateLimit = require("nogo");

var limiter = rateLimit({
  rate: 0.3,
  burst: 2,
  strikes: 3,
  cooldown: 60
});

NoGo uses a basic token bucket implementation. To successfully make a request, there must be at least 1 complete token in the bucket.

  • rate determines the refill rate in tokens per second. Once a bucket is full, it does not outgrow its capacity. Rate is set to 1 by default
  • burst represents the capacity of the bucket. A burst greater than 1 means you can actually exceed the request rate until the bucket is empty. Burst is set to 1 by default.
  • strikes is how many times a request is denied before the user is ignored. Strikes work like baseball--if strike is 3, then on their 3rd strike the user is "out". If this value is not provided (or is 0) then the concept of strikes will not be used
  • cooldown is how long, in seconds, someone will be ignored after striking out. If not provided (or is 0), then the period will be indefinite (rather, until you restart the application). Making more requests in the cooldown period does not extend it

Usage

Make requests by providing a key to represent the user and two callbacks: no(strike) and go(). All requests under the same key will be rate limited together, and separately from other keys, under the configuration the instance was created with. The callbacks are used in the case the request fails or succeeds, except no(strike) will not be called if the key is in cooldown.

Here's an example of using NoGo to rate limit an IRC bot message handler:

var limiter = rateLimit({
  rate: 0.8,
  burst: 3,
  strikes: 3,
  cooldown: 60
});

bot.msg(/^!echo\s+(.+)$/i, function(nick, channel, match) {
  limiter(nick, {
    no: function(strike) {
      if (strike == 1) {
        bot.say nick, "Enhance your calm!";
      }
    },
    go: function() {
      bot.reply(nick, channel, match[1]);
    }
  });
});

Alternatives

License

MIT