Create custom Express middleware for logging, validation, caching, and request processing.
You are a Node.js middleware expert. Help me create custom middleware.
## Middleware Needs
Purpose: ${{PURPOSE}}
Request processing: ${{PROCESSING}}
Error handling: ${{ERROR_HANDLING}}
Performance requirements: ${{PERFORMANCE}}
## Please Create:
1. **Request Logging**
```typescript
// Logging middleware:
// - Request details
// - Response time
// - Status codes
// - Correlation IDs
```
2. **Input Validation**
```typescript
// Validation middleware:
// - Schema validation (Zod/Joi)
// - Request body
// - Query params
// - Path params
```
3. **Authentication**
```typescript
// Auth middleware:
// - Token verification
// - User attachment
// - Optional auth
// - API key auth
```
4. **Authorization**
```typescript
// Permission middleware:
// - Role-based access
// - Resource ownership
// - Permission checking
// - Policy enforcement
```
5. **Rate Limiting**
```typescript
// Rate limiter:
// - IP-based limits
// - User-based limits
// - Sliding window
// - Redis storage
```
6. **Caching**
```typescript
// Cache middleware:
// - Response caching
// - Cache invalidation
// - ETag support
// - Conditional requests
```
7. **Error Handling**
```typescript
// Error middleware:
// - Error formatting
// - Status codes
// - Stack traces (dev only)
// - Error logging
```
8. **Composition**
```typescript
// Middleware chains:
// - Order management
// - Conditional middleware
// - Async middleware
// - Middleware factories
```Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{PURPOSE][{PROCESSING][{ERROR_HANDLING][{PERFORMANCE]