# toNodeHandler

<!-- https://uncage.vercel.app/docs/api/hub/node/functions/tonodehandler/ -->

```ts
function toNodeHandler(h): UncageNodeHandler;
```

Defined in: hub/src/node/node-handler.ts:29

The hub as a Node `(req, res, next?)` middleware for Express, Connect, Fastify
(`reply.hijack()` then `handler(request.raw, reply.raw)`) and `node:http`:

  app.use(toNodeHandler(hub));                 // or app.use('/api/uncage', toNodeHandler(hub))
  attachWebSocket(hub, server);                // machine WebSockets on the same HTTP server

Only requests under `hub.basePath` are handled; anything else goes to `next()` untouched (with no
`next`, e.g. plain `node:http`, it gets a 404). Paths are read from `req.originalUrl` (Express) or
`req.url`, so mounting under the prefix works too. Mount before body parsers. The client IP
for rate limits is Express's `req.ip` (set `app.set('trust proxy', …)` behind a proxy), else the
socket address.

## Parameters

| Parameter | Type |
| ------ | ------ |
| `h` | [`Hub`](https://uncage.vercel.app/docs/api/hub/hub/interfaces/hub.md) |

## Returns

[`UncageNodeHandler`](https://uncage.vercel.app/docs/api/hub/node/type-aliases/uncagenodehandler.md)
