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

rate-limiter-sentry

v1.0.1

Published

The `rate-limiter` npm package is a powerful and flexible rate-limiting middleware designed for microservices and distributed systems. It supports various data sources, such as Node cache and Redis, and can be seamlessly integrated into any Node.js librar

Downloads

2

Readme

Rate Limiter NPM Package

Overview

The rate-limiter npm package is a powerful and flexible rate-limiting middleware designed for microservices and distributed systems. It supports various data sources, such as Node cache and Redis, and can be seamlessly integrated into any Node.js library. The primary goal is to prevent resource starvation, improving the availability of API-based services by mitigating unintentional load-based denial-of-service incidents.

Objective ❄️

Prevent resource starvation and improve the availability of API-based services by enforcing rate limits, ensuring fair resource utilization.

Success Criteria 🎯

Ensure that no IP address can make requests beyond the permitted limit within the defined interval window.

Features 💡

  • IP-Based Rate Limiting: Restricts the number of requests from a specific IP address within a defined time window.

  • App-level Rate Limiting: Limits the total number of requests for the entire application, irrespective of the IP address.

  • Easy Setup: Simple configuration and setup using Redis credentials. Quick integration through middleware.

Quick Start ⭐️

  1. Install the package:

    npm install [email protected]
  2. Set the environment variable for rate limiting:

    RATE_LIMIT_HEADER=true
  3. Add the middleware to your server:

    const initRateLimit = require('rate-limiter');
    const rateLimitConfig = require('./rateLimitConfig');
    
    app.use(
      '/your-api-endpoint',
      await initRateLimit(rateLimitConfig, { ...listeners })
    );

Configuration ⚙️

Modify the environment.js and rateLimitConfig.js files based on your application's requirements.

environment.js:

module.exports = {
  appName: 'your-app',
  redis: {
    port: process.env.REDIS_PORT || null,
    uri: process.env.REDIS_URI || null,
  },
  rateLimit: {
    // ...other configurations
  },
  isRateLimitEnabled: process.env.RATE_LIMIT_ENABLED || false,
};

rateLimitConfig.js:

const {
  appName,
  redis,
  rateLimit: rateLimitConfig,
  isRateLimitEnabled,
} = require('./environment');

module.exports = {
  appName,
  databaseConfig: {
    database: 'redis', // accepts 'redis' or 'nodecache'
    clusterMode: true, // boolean if redis is in cluster mode
    credentials: [
      {
        port: redis.port,
        host: redis.uri,
      },
    ],
  },
  rateLimitConfig,
  isRateLimitEnabled,
};

Error Debugging 🐛

To aid in debugging, set the RATE_LIMIT_HEADER=true environment variable for detailed response headers. Analyze the headers:

  • x-ratelimit-limit: Max request hits
  • x-ratelimit-remaining: Number of requests remaining
  • x-ratelimit-reset: Remaining window time for reset in seconds.

Recommendations 🔴

For development environments, set RATE_LIMIT_HEADER=true. Adjust other configurations based on your application's needs.

Log on Successful Implementation ⚪

Upon successful implementation, log network calls to the application backend with the specified response headers.

Good Bye 🎉

Feel free to reach out if you encounter any issues or need further assistance. Happy coding! 🚀