Body Size Limiting
Limit request body size to prevent memory issues and protect against denial-of-service attacks.
Basic Body Size Limiting
MoroJS provides built-in body size limiting middleware to prevent memory exhaustion and protect against large payload attacks.
Global Body Size Limit
typescript
Body Size Features
- • Global and per-route body size limits
- • Support for different content types
- • Human-readable size formats (mb, kb, etc.)
- • Custom error messages
- • Automatic request rejection for oversized payloads
Per-Route Limits
Route-Specific Body Size Limits
typescript
Best Practices
Do
- • Set appropriate limits for each route
- • Use stricter limits for JSON endpoints
- • Set higher limits for file upload endpoints
- • Provide clear error messages
- • Monitor body size violations
- • Use different limits per content type
Don't
- • Set unlimited body sizes
- • Use the same limit for all routes
- • Ignore body size limits
- • Set limits too high for security
- • Skip body size validation
- • Allow very large JSON payloads