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 🙏

© 2025 – Pkg Stats / Ryan Hefner

http-ratelimit

v0.2.3

Published

Determines whether an IP address has exceeded the previously specified limit of requests per timeframe

Downloads

30

Readme

HTTP-RateLimit v0.2.3

This package counts the incoming client requests and determines whether a requesting client has reached a specified request threshold per defined timeframe

Installation:

npm i http-ratelimit

Example Usage:

const http = require("http"); // also works with the https package
const rateLimit = require("http-ratelimit");


http.createServer((req, res) => {
    rateLimit.inboundRequest(req); // this function has to run in the createServer callback, optimally at the very top of it like shown here

    if(rateLimit.isRateLimited(req, 20) === true) { // this checks whether the request is from an IP that has already sent x amount of requests in the defined timeframe (two minutes in this example). x is specified with the second attribute.
        // if this part is reached, that means the requester has sent more than 20 requests in two minutes
        // it is best to end the request here with status code 429, like the following lines suggest:

        res.writeHead(429, {"Content-Type": "text/plain; utf-8"});
        res.end("Too many requests - max is 20 requests in two minutes");
    }
    else {
        // the requester has sent less than 20 requests in the defined timeframe (two minutes in this example)
        // do your normal stuff here

        res.writeHead(200, {"Content-Type": "text/plain; utf-8"});
        res.end("https://data.whicdn.com/images/325197845/superthumb.jpg");
    }

}).listen(80, null, err => {
    if(!err) {
        // server was successfully started
        rateLimit.init(2, true); // HTTP-RateLimit has to be initialized before running any other function. It's best to put it right in here.
        // In this example, a timeframe of two minutes is chosen (first parameter) - (defaults to 1 if left undefined)
        // If you are using a reverse proxy, the second parameter has to be set to true - (defaults to false if left undefined)

        console.log("success");
    }
    else {
        // error while starting server
        console.log(`Error: ${err}`);
        process.exit(1);
    }
});

Function List:

  • rateLimit.init(timeframe: Number, usingReverseProxy: Boolean) - Initializes all variables etc. | If you are using a reverse proxy, make sure to set the second parameter to true as then the IP address has to be pulled from the "x-forwarded-for" request header
  • rateLimit.inboundRequest(req: http.IncomingMessage) - Adds the requestee's IP address to the list of requests per timeframe
  • rateLimit.isRateLimited(req: http.IncomingMessage, requestLimitPerMinute: Number) - Checks if the request's IP address occurs more than requestLimitPerMinute times in the above mentioned list and should therefore be rate limited | Returns true or false

Back to the Top