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-rate-limit-spider

v1.0.7

Published

A middleware for rate limiting in ExpressJS.

Downloads

9

Readme

express-rate-limit-spider

express-rate-limit-spider is a middleware for rate limiting web crawling or spidering activities in Express applications. It allows you to restrict the number of requests made by web crawlers within a specified time interval, helping to prevent excessive crawling and protect your server resources.

Benchmarks:

  • express-rate-limit x 222,950 ops/sec ±29.79% (63 runs sampled)
  • express-rate-limit-spider x 504,694,760 ops/sec ±0.41% (90 runs sampled)

Fastest is express-rate-limit-spider

Installation

You can install express-rate-limit-spider using npm:

npm install express-rate-limit-spider

Usage

To use express-rate-limit-spider in your Express application, follow these steps:

1.Import the middleware into your project:

const rateLimitSpider = require('express-rate-limit-spider');

2.Define the rate limit configuration:

const limit = 10; // Maximum number of requests allowed by the spider within the interval
const interval = 60000; // Interval duration in milliseconds (e.g., 60 seconds)
const timeout = 0; // Optional timeout duration in milliseconds (0 for no timeout)

3.Apply the middleware to the desired routes:

app.use(rateLimitSpider(limit, interval, timeout));

The middleware will automatically track and limit the number of requests made by web crawlers based on the specified configuration.

Configuration Options

The express-rate-limit-spider middleware accepts the following configuration options:

  • limit: Maximum number of requests allowed by the spider within the interval.
  • interval: Interval duration in milliseconds. The middleware resets the request count for each spider after this interval.
  • timeout (optional): Timeout duration in milliseconds. If set to a non-zero value, the request count for each spider will be reset to 0 after this timeout.

Error Handling

When the rate limit is exceeded by a spider, the middleware responds with a 429 Too Many Requests status code and a JSON object containing an error message:

{
  "error": "Rate limit exceeded"
}

If an internal server error occurs during rate limiting, the middleware responds with a 500 Internal Server Error status code and a JSON object containing an error message:

{
  "error": "Internal server error"
}

Usage Considerations

It's important to note that express-rate-limit-spider identifies spiders based on the User-Agent header in the incoming requests. Make sure that the web crawlers you want to limit have unique and identifiable user agent strings.

License

MIT