#express

15 snippets tagged with #express

typescriptintermediate

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

#jwt#express
typescriptintermediate

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

#express#rate-limit
typescriptbeginner

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

#express#async
typescriptintermediate

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

#express#upload
typescriptadvanced

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

#stream#download
typescriptbeginner

Express Zod Request Validation

Validate Express request body, params, and query with Zod schemas via reusable middleware.

Best for: API input validation

#express#zod
typescriptintermediate

Express Error Handling Middleware

Centralized error handling in Express with custom error classes, async wrapper, and structured responses.

Best for: API error standardization

#nodejs#express
typescriptintermediate

Request ID Tracing Middleware

Express middleware that generates or forwards X-Request-Id headers for distributed tracing.

Best for: Distributed tracing

#express#tracing
typescriptintermediate

ETag Caching Middleware

Express middleware that generates ETags and handles 304 Not Modified responses for bandwidth savings.

Best for: API caching

#express#caching
typescriptintermediate

IP Geolocation Middleware

Extracts client IP and attaches geolocation data to the request using a lightweight lookup.

Best for: Content localization

#express#geolocation
typescriptintermediate

Response Compression Middleware

Native zlib-based middleware that gzip-compresses responses above a size threshold.

Best for: Reducing API payload size

#express#compression
typescriptbeginner

Request Timeout Middleware

Express middleware that aborts requests exceeding a configurable time limit with 408 status.

Best for: Preventing hanging requests

#express#timeout
typescriptbeginner

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

#express#authentication
typescriptbeginner

Structured Request Logger Middleware

Express middleware that logs request/response details as structured JSON with timing information.

Best for: API monitoring

#express#logging
typescriptintermediate

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

#health-check#monitoring