> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tappify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# toExpress

> Wraps the handler as Express middleware, for a server that speaks Express rather than fetch.

```ts theme={null}
function toExpress(handler): ExpressMiddleware;
```

Wraps the handler as Express middleware, for a server that speaks Express
rather than `fetch`.

## Parameters

### handler

[`TappifyFetchHandler`](/extensions/reference/server-api/TypeAlias.TappifyFetchHandler)

## Returns

[`ExpressMiddleware`](/extensions/reference/server-api/TypeAlias.ExpressMiddleware)

## Remarks

It builds the url from `originalUrl` and the `host` header, forwards every
header, and takes the body from `request.body` when a parser has already read
it or from the stream when none has. A request with neither — a parser that
consumed the stream without leaving a body — fails with a `TapServerError`
carrying `TAP_BODY_INVALID` rather than calling your handler against an empty
body, so mount `express.json()` before this middleware or mount this one first.
A `TapServerError` is written as the handler's own JSON error; anything else
goes to `next`, so your own error middleware sees it.

## Example

```ts theme={null}
import { createTappifyHandler, toExpress } from '@tappify/extension-sdk/server';

const middleware = toExpress(
  createTappifyHandler({ extensionId: 'starter', health: () => ({ ok: true }) }),
);
```
