This Node.js application demonstrates a basic API rate limiter using Express and Redis. It includes middleware for system-wide, client-specific, and monthly quota rate limiting. Here is a deployed example: https://api-rate-limiter-0-77bc71fe30d5.herokuapp.com/test?id=123
Make sure you have the following installed:
- Clone the repository:
git clone https://github.com/drayzii/api-rate-limiter.git
cd api-rate-limiter- Install dependencies
npm installCreate a .env file in the project root and set your environment variables:
PORT=
CLIENT_LIMIT_PER_MINUTE=
CLIENT_MONTHLY_LIMIT=
SYSTEM_LIMIT_PER_MINUTE=Start the server:
npm startThe server will run at http://localhost:3000 (or the specified PORT).
Run tests:
npm test- Description: Test route to check the functionality.
- Parameter:
id: Client ID for rate limiting. Example:/test?id=123
- The application implements rate limiting for system-wide, client-specific, and monthly quotas. The configured limits can be found in the
.envfile. - We can connect to a centralised Redis server to ensure that all instances of our application share the same rate limit counters.