Middleware Use Cases
Middleware is useful for lightweight request-level logic such as redirects, rewrites, locale detection, and certain authentication-related routing decisions.
It should not become a general-purpose business-logic layer. Expensive database operations, complex business workflows, and large application services usually belong elsewhere.
Always consider the runtime and deployment constraints of middleware before importing libraries that depend on Node-specific APIs.
Key Takeaways
- Use middleware for lightweight request interception.
- Keep heavy business logic out of middleware.
- Understand the runtime supported by your deployment environment.