This repository provides a comprehensive implementation of rate limiting using Node.js and Express. The project showcases best practices in applying global and route-specific rate limits to prevent abuse and ensure fair usage.
- Features
- Tech Stack
- Prerequisites
- Setup
- API Endpoints
- Rate Limiting Details
- Contributing
- License
- Links
- Global Rate Limiting: Limits the number of requests per IP address to prevent abuse.
- Login Rate Limiting: Specifically limits login attempts to mitigate brute force attacks.
- Security Enhancements: Utilizes Helmet for basic security improvements.
- Backend: Node.js, Express
- Rate Limiting: express-rate-limit
- Security: Helmet
- Environment Management: dotenv
Ensure you have the following installed and configured on your machine:
- Node.js: Version 14 or higher. Download here.
- MySQL: MySQL server or a compatible database for future expansions. Download here.
For installation assistance, refer to the official documentation or guides.
-
Clone the repository:
git clone https://github.com/AchrefDevTN/rate-limiting.git
-
Navigate into the project directory:
cd rate-limiting
-
Install dependencies:
npm install
-
Create a .env file in the root directory: (Copy the contents below and configure your environment variables)
PORT=5000
-
Run the application:
- For development
npm run dev
- For production
npm start
-
Access the API:
- The server will be running on
http://localhost:5000
-
GET
/api/
Returns a welcome message.
Response:{ "message": "Welcome to the Rate Limiting API!" }
-
POST
/api/login
Logs in a user and applies rate limiting.
Request body:{ "username": "string", "password": "string" }
Response:
{ "message": "Login successful" }
- Limits: 100 requests per 15 minutes per IP
- Message: Too many requests from this IP, please try again later.
- Limits: 5 login attempts per 15 minutes per IP
- Message: Too many login attempts from this IP, please try again later.
If you have suggestions or improvements, please submit an issue or pull request. Contributions are welcome!
This project is licensed under the MIT License. See the LICENSE file for details.
Node.js | Express | Rate Limiting | License |
---|---|---|---|