Skip to main content
A production-ready middleware pattern for Express applications.

Install

Basic Middleware

middleware/auth.ts

Use the Middleware

app.ts

With Rate Limit Headers

Include rate limit info in response headers:
middleware/auth.ts

Permission-Based Access

Create middleware that requires specific permissions:
middleware/permissions.ts
Use it:

Configurable Middleware Factory

Create a flexible middleware that can be configured per-route:
middleware/auth.ts

Error Handling

Graceful degradation when Unkey is unavailable:
middleware/auth.ts

TypeScript Setup

types/express.d.ts
Make sure to include this in your tsconfig.json:
Last modified on May 6, 2026