• Version 5.0.1
  • Published
  • 32.5 kB
  • 3 dependencies
  • MIT license


npm i compose-middleware
yarn add compose-middleware
pnpm add compose-middleware


Compose an array of middleware into a single function for use in Express, Connect, router, etc.



function compose

compose: <T, U, V = void>(
...handlers: Handler<T, U, V>[]
) => RequestHandler<T, U, V>;
  • Compose an array of middleware handlers into a single handler.

function errors

errors: <T, U, V = void>(
...handlers: Handler<T, U, V>[]
) => ErrorHandler<T, U, V>;
  • Wrap middleware handlers.

Type Aliases

type ErrorHandler

type ErrorHandler<T, U, V = void> = (err: Error, req: T, res: U, next: Next<V>) => V;

    type Handler

    type Handler<T, U, V = void> =
    | Middleware<T, U, V>
    | flatten.NestedArray<Middleware<T, U, V>>;

      type Middleware

      type Middleware<T, U, V = void> = RequestHandler<T, U, V> | ErrorHandler<T, U, V>;

        type Next

        type Next<T = void> = (err?: Error | null) => T;

          type RequestHandler

          type RequestHandler<T, U, V = void> = (req: T, res: U, next: Next<V>) => V;

            Package Files (1)

            Dependencies (3)

            Dev Dependencies (8)

            Peer Dependencies (0)

            No peer dependencies.


            To add a badge like this badgeto your package's README, use the codes available below.

            You may also use to create a custom badge linking to

            • Markdown
            • HTML
              <a href=""><img src="" alt=""></a>