---
lang: en
title: 'API docs: express.middlewareregistry.middleware'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/strongloop/loopback-next/tree/master/packages/express
permalink: /doc/en/lb4/apidocs.express.middlewareregistry.middleware.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/express](./express.md) &gt; [MiddlewareRegistry](./express.middlewareregistry.md) &gt; [middleware](./express.middlewareregistry.middleware.md)

## MiddlewareRegistry.middleware() method

Register a middleware function or provider class

<b>Signature:</b>

```typescript
middleware(middleware: Middleware | Constructor<Provider<Middleware>>, options?: MiddlewareBindingOptions): Binding<Middleware>;
```

## Parameters

|  Parameter | Type | Description |
|  --- | --- | --- |
|  middleware | [Middleware](./express.middleware.md) \| [Constructor](./context.constructor.md)<!-- -->&lt;[Provider](./context.provider.md)<!-- -->&lt;[Middleware](./express.middleware.md)<!-- -->&gt;&gt; | Middleware function or provider class |
|  options | [MiddlewareBindingOptions](./express.middlewarebindingoptions.md) | Middleware binding options |

<b>Returns:</b>

[Binding](./context.binding.md)<!-- -->&lt;[Middleware](./express.middleware.md)<!-- -->&gt;

## Example


```ts
const log: Middleware = async (requestCtx, next) {
  // ...
}
server.middleware(log);

```


