{"id":29223015,"url":"https://github.com/aldoignatachandra/nodejs-rate-limiter","last_synced_at":"2026-05-07T17:37:23.093Z","repository":{"id":302086820,"uuid":"1011040818","full_name":"aldoignatachandra/NodeJS-Rate-Limiter","owner":"aldoignatachandra","description":"A comprehensive implementation of API rate limiting strategies in Node.js with Redis","archived":false,"fork":false,"pushed_at":"2025-06-30T14:01:53.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-30T14:26:57.499Z","etag":null,"topics":["node-js","rate-limiter","redis","rest-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aldoignatachandra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-30T08:03:32.000Z","updated_at":"2025-06-30T14:01:56.000Z","dependencies_parsed_at":"2025-06-30T14:27:56.299Z","dependency_job_id":"fc70989a-11af-4bee-a5ce-476218d083c3","html_url":"https://github.com/aldoignatachandra/NodeJS-Rate-Limiter","commit_stats":null,"previous_names":["aldoignatachandra/nodejs-rate-limiter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aldoignatachandra/NodeJS-Rate-Limiter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldoignatachandra%2FNodeJS-Rate-Limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldoignatachandra%2FNodeJS-Rate-Limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldoignatachandra%2FNodeJS-Rate-Limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldoignatachandra%2FNodeJS-Rate-Limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aldoignatachandra","download_url":"https://codeload.github.com/aldoignatachandra/NodeJS-Rate-Limiter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aldoignatachandra%2FNodeJS-Rate-Limiter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263257528,"owners_count":23438449,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["node-js","rate-limiter","redis","rest-api"],"created_at":"2025-07-03T04:23:57.173Z","updated_at":"2026-05-07T17:37:23.051Z","avatar_url":"https://github.com/aldoignatachandra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js Rate Limiter Demo\n\n![Node.js](https://img.shields.io/badge/Node.js-20.x-green)\n![Express](https://img.shields.io/badge/Express-4.x-blue)\n![Redis](https://img.shields.io/badge/Redis-4.x-red)\n![ES Modules](https://img.shields.io/badge/ES%20Modules-%E2%9C%93-lightgrey)\n\nA comprehensive implementation of API rate limiting strategies in Node.js with Redis, designed for production-ready applications.\n\n## 📋 Overview\n\nThis project demonstrates an implementation of rate limiting in Node.js backend applications using Express and Redis. It showcases multiple advanced rate limiting strategies through a clean, modular architecture that follows industry best practices.\n\n## ✨ Features\n\n- Modern ES6+ JavaScript with ES module syntax\n- **Express.js** REST API with clean architecture patterns\n- Advanced **rate limiting** using `rate-limiter-flexible`\n- **Redis** integration for distributed rate limiting across multiple server instances\n- Multiple rate limiting strategies ( Fixed Window, Sliding Window, Token Bucket )\n- IP-based and user-based limiting approaches\n- Custom middleware implementation\n- Comprehensive error handling\n- Rate limit headers following RFC standards\n- Well-structured codebase following software engineering best practices\n\n## 🔧 Prerequisites\n\n- `Node.js v20+` ( ES modules support )\n- `Redis server 6.0+` ( local or remote )\n- `npm` or `yarn` package manager\n\n## 📦 Installation\n\n1. Clone the repository :\n\n```bash\ngit clone https://github.com/aldoignatachandra/NodeJS-Rate-Limiter.git\ncd nodejs-rate-limiter\n```\n\n2. Install dependencies :\n\n```bash\nnpm install\n# OR using yarn\nyarn install\n```\n\n3. Configure environment variables :\n\n```bash\n# Create .env file from example\ncp .env.example .env\n# Edit the .env file with your preferred settings\n```\n\n4. Start Redis :\n\n```bash\n# Using provided script\n./start-redis.sh\n# OR using Docker directly\ndocker run --name redis-rate-limiter -p 6379:6379 -d redis:alpine\n```\n\n5. Start the application :\n\n```bash\n# Development mode with hot-reloading\nnpm run dev\n# OR using yarn\nyarn dev\n\n# Production mode\nnpm start\n# OR using yarn\nyarn start\n```\n\n## 🚦 Rate Limiting Strategies\n\nThe project implements these advanced rate limiting approaches:\n\n1. Fixed Window Rate Limiting\n\nLimits requests to a fixed number within a specific time window (e.g., 100 requests per 15 minutes). Simple but can lead to traffic spikes at window boundaries.\n\n```javascript\n// Example configuration\n{\n  points: 100,         // Number of allowed requests\n  duration: 60 * 15    // Window size in seconds (15 minutes)\n}\n```\n\n2. Sliding Window Rate Limiting\n\nMore sophisticated approach that provides smoother request distribution by constantly moving the window forward.\n\n```javascript\n// Example configuration\n{\n  points: 100,         // Number of allowed requests\n  duration: 60 * 15,   // Window size in seconds\n  execEvenly: true     // Distributes requests evenly\n}\n```\n\n3. Token Bucket Rate Limiting\n\nModels rate limiting as a bucket of tokens that refill at a constant rate, allowing for burst handling )\n\n```javascript\n// Example configuration\n{\n  points: 100,                  // Bucket size\n  duration: 3600,               // Refill period\n  inmemoryBlockOnConsumed: 100  // Block when bucket is empty\n}\n```\n\n4. IP-based Rate Limiting\n\nDifferent limits for different IP addresses or IP ranges.\n\n5. User-based Rate Limiting\n\nDifferent limits based on authentication status (authenticated users vs. anonymous).\n\n## 📡 API Endpoints\n\n| Endpoint     | Method | Rate Limit       | Description                                |\n| ------------ | ------ | ---------------- | ------------------------------------------ |\n| /api/public  | GET    | 100 req / 15 min | Standard endpoint with basic rate limiting |\n| /api/premium | GET    | 500 req / 15 min | Premium endpoint with higher rate limits   |\n| /api/status  | GET    | 1000 req / hour  | Status endpoint to check remaining quota   |\n\nAll endpoints return rate limit information in the response headers:\n\n- **X-RateLimit-Limit**: Maximum requests allowed in the window\n- **X-RateLimit-Remaining**: Remaining requests in the current window\n- **X-RateLimit-Reset**: Time when the rate limit window resets (ISO format)\n- **Retry-After**: Seconds until retry is allowed (only when rate limited)\n\n## 🔑 Environment Variables\n\n| Variable  | Description                                 | Default Value          |\n| --------- | ------------------------------------------- | ---------------------- |\n| NODE_ENV  | Environment (development, production, test) | development            |\n| PORT      | Port for the HTTP server                    | 3000                   |\n| REDIS_URI | Redis connection string                     | redis://localhost:6379 |\n\n## 📁 Project Structure\n\n```\nnodejs-rate-limiter/\n├── src/\n│   ├── api_doc/                      # Postman API Documentation\n│   ├── config/                       # Application configuration\n│   │   └── index.js                  # Central configuration management\n│   ├── controllers/                  # Request handlers\n│   │   └── api_controller.js         # API endpoint controllers\n│   ├── middleware/                   # Express middleware\n│   │   ├── error_handler.js          # Global error handling\n│   │   └── rate_limiter.js           # Rate limiting middleware\n│   ├── routes/                       # API routes definitions\n│   │   └── api_routes.js             # API endpoint routing\n│   ├── utils/                        # Utility functions\n│   │   ├── rate_limit_strategies.js  # Rate limit implementation strategies\n│   │   └── redis.js                  # Redis client configuration\n│   └── app.js                        # Application entry point\n├── .env                              # Environment variables\n├── .gitignore                        # Git ignore configuration\n├── package.json                      # Project dependencies and scripts\n├── README.md                         # Project documentation\n├── start-redis.sh                    # Helper script to start Redis\n└── test-rate-limit.js                # Test script for rate limiting\n```\n\n## 🧪 Testing Rate Limits\n\nUse the included test script to see rate limiting in action:\n\n```bash\n# Test standard endpoint with default settings (150 requests)\nnode test-rate-limit.js\n\n# Test premium endpoint with 200 requests\nnode test-rate-limit.js premium 2000\n\n# Test public endpoint with 100 requests, 5 at a time\nnode test-rate-limit.js public 100 5\n```\n\n## 🔧 Development\n\nFormat code using Prettier:\n\n```bash\nnpm run format\n# OR\nyarn format\n```\n\n## 📚 Technical Implementation\n\n- **Rate Limiter**: Uses rate-limiter-flexible for its robust implementation and Redis support\n- **Redis Integration**: Implements distributed rate limiting for multi-server setups\n- **ES Module Syntax**: Uses modern JavaScript with import/export statements\n- **Error Handling**: Comprehensive error handling with appropriate status codes\n- **Headers**: Follows standard practices for rate limit headers\n\n## 👨‍💻 Author\n\nCreated with 💻 by Ignata\n\n- 📂 GitHub: [Aldo Ignata Chandra](https://github.com/aldoignatachandra)\n- 💼 LinkedIn: [Aldo Ignata Chandra](https://linkedin.com/in/aldoignatachandra)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faldoignatachandra%2Fnodejs-rate-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faldoignatachandra%2Fnodejs-rate-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faldoignatachandra%2Fnodejs-rate-limiter/lists"}