#express
15 snippets tagged with #express
JWT Verify Middleware
Express middleware that verifies JWT tokens from the Authorization header and attaches the decoded payload to the request.
Best for: REST API authentication
In-Memory Rate Limiter for Express
Token bucket rate limiter middleware for Express with configurable window and max requests per IP.
Best for: API abuse prevention
Async Error Handler Wrapper
Higher-order function that wraps async Express route handlers and forwards rejected promises to error middleware.
Best for: Express route error handling
File Upload with Multer
Configure Multer for disk storage with file type validation, size limits, and unique filenames for Express.
Best for: Profile avatar uploads
Stream File Download
Express handler that streams a file to the client with proper headers, range support, and error handling.
Best for: Large file downloads
Express Zod Request Validation
Validate Express request body, params, and query with Zod schemas via reusable middleware.
Best for: API input validation
Express Error Handling Middleware
Centralized error handling in Express with custom error classes, async wrapper, and structured responses.
Best for: API error standardization
Request ID Tracing Middleware
Express middleware that generates or forwards X-Request-Id headers for distributed tracing.
Best for: Distributed tracing
ETag Caching Middleware
Express middleware that generates ETags and handles 304 Not Modified responses for bandwidth savings.
Best for: API caching
IP Geolocation Middleware
Extracts client IP and attaches geolocation data to the request using a lightweight lookup.
Best for: Content localization
Response Compression Middleware
Native zlib-based middleware that gzip-compresses responses above a size threshold.
Best for: Reducing API payload size
Request Timeout Middleware
Express middleware that aborts requests exceeding a configurable time limit with 408 status.
Best for: Preventing hanging requests
API Key Authentication Middleware
Simple API key validation middleware that checks the X-API-Key header against a set of valid keys.
Best for: Public API authentication
Structured Request Logger Middleware
Express middleware that logs request/response details as structured JSON with timing information.
Best for: API monitoring
Health Check Endpoint with Dependency Checks
Express health check endpoint that verifies database, Redis, and disk connectivity with status reporting.
Best for: Kubernetes liveness and readiness probes