Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/koajs/response-time

X-Response-Time middleware
https://github.com/koajs/response-time

Last synced: 2 months ago
JSON representation

X-Response-Time middleware

Awesome Lists containing this project

README

        

# koa-response-time

[![Greenkeeper badge](https://badges.greenkeeper.io/koajs/response-time.svg)](https://greenkeeper.io/)

X-Response-Time middleware for [koa](https://github.com/koajs/koa). Compatible with [request-received](https://github.com/cabinjs/request-received).

## Installation

```js
$ npm install koa-response-time
```

## Usage

Basic usage:

```js
const Koa = require('koa');
const responseTime = require('koa-response-time');
const app = new Koa();

app.use(responseTime());
```

If you need response high resolution in nano time, set `hrtime` option to `true`:

```js
app.use(responseTime({ hrtime: true }));
```

Sample response header with `hrtime = false` (default):

```
X-Response-Time: 153ms
```

Sample response header with `hrtime = true`:

```
X-Response-Time: 153.123581ms
```

## Note

Best to `.use()` at the _top_ before any other middleware,
to wrap all subsequent middleware.

## License

MIT