Skip to main content
The Factory Helper provides utilities for creating type-safe Hono applications, middleware, and handlers with proper type inference.

Import

Functions

createFactory()

Creates a factory instance for creating type-safe Hono components.
(app: Hono<E>) => void
Optional function to initialize new app instances
HonoOptions<E>
Default options for created apps
Factory<E, P>
A factory instance with methods for creating apps, middleware, and handlers
Example

createMiddleware()

Creates type-safe middleware without needing a factory instance.
MiddlewareHandler
required
The middleware handler function
MiddlewareHandler
The same middleware with proper type inference
Example

Factory Methods

factory.createApp()

Creates a new Hono application instance.
HonoOptions<E>
Options for the Hono app (merged with default options)
Hono<E>
A new Hono application instance
Example

factory.createMiddleware()

Creates type-safe middleware with the factory’s environment types.
MiddlewareHandler
required
The middleware handler function
MiddlewareHandler
Type-safe middleware
Example

factory.createHandlers()

Creates an array of type-safe handlers.
H[]
required
Variable number of handler functions
H[]
Array of handlers with proper type inference
Example

Examples

Basic Factory Usage

Reusable Middleware Factory

Modular App Structure

Typed Input Validation

Benefits

Type Safety

The factory ensures all components share the same environment types:

Reusability

Create reusable middleware and handlers:

Consistent Setup

Initialize all apps with common configuration: