Backend Boilerplates
javascript
Intermediate
Express In-Memory Rate Limiter
Simple in-memory rate limiter for Express using a Map — no Redis needed for small apps.
javascript
const store = new Map();
module.exports = (limit = 100, windowMs = 60000) => (req, res, next) => {
const key = req.ip;
const now = Date.now();
const data = store.get(key) || { count: 0, start: now };
if (now - data.start > windowMs) { data.count = 0; data.start = now; }
data.count++;
store.set(key, data);
if (data.count > limit) return res.status(429).json({ error: 'Too many requests' });
next();
};
Prerequisites
- express >= 4.x
Pro Tips
- → Use Redis for distributed rate limiting.
Commercial Licensing
Acquire a production access token or template license for enterprise deployment.
Module Info
- Language
- javascript
- Level
- Intermediate
- Read time
- 3 min
- Published
- Aug 2024
- License
- Commercial License
Newsletter
New modules every week, directly to your inbox.
Similar Modules
Laravel Artisan Seeder Command
Artisan command to re-seed production data with a confirmation prompt.
php
·
Intermediate
CSV to PostgreSQL Bulk Loader
Stream a large CSV directly into PostgreSQL using COPY for maximum throughput.
python
·
Intermediate
Go Event Sourcing Store
Minimal append-only event store in Go backed by a Postgres table.
go
·
Advanced