# koa-better-timeout

> Response timeout middleware for Koa and Lad (uses Boom by default)

Latest version **0.0.6** (published 2020-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-better-timeout
pnpm add koa-better-timeout
yarn add koa-better-timeout
bun add koa-better-timeout
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2020-07-23 |
| First published | 2017-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.3 |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Nick Baugh |
| Maintainers | niftylettuce |
| Keywords | delay, handler, koa, lad, lag, lass, next, response, settimeout, timeout, v2 |

## Links

- npm: https://www.npmjs.com/package/koa-better-timeout
- Repository: https://github.com/ladjs/koa-better-timeout
- Issues: https://github.com/ladjs/koa-better-timeout/issues
- npm.io page: https://npm.io/package/koa-better-timeout

## Dependencies (1)

- [@hapi/boom](https://npm.io/package/@hapi/boom.md) ^9.1.0

## Recent versions

- 0.0.6 (latest) — 2020-07-23
- 0.0.5 — 2020-07-23
- 0.0.4 — 2019-09-05
- 0.0.3 — 2019-01-13
- 0.0.2 — 2017-09-26
- 0.0.1 — 2017-09-10

## README

# koa-better-timeout

[![build status](https://img.shields.io/travis/ladjs/koa-better-timeout.svg)](https://travis-ci.org/ladjs/koa-better-timeout)
[![code coverage](https://img.shields.io/codecov/c/github/ladjs/koa-better-timeout.svg)](https://codecov.io/gh/ladjs/koa-better-timeout)
[![code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![made with lass](https://img.shields.io/badge/made_with-lass-95CC28.svg)](https://lass.js.org)
[![license](https://img.shields.io/github/license/ladjs/koa-better-timeout.svg)](<>)

> Response timeout middleware for [Koa][] and [Lad][] (uses [Boom][] by default)


## Table of Contents

* [Install](#install)
* [Usage](#usage)
* [Options](#options)
* [Contributors](#contributors)
* [License](#license)


## Install

[npm][]:

```sh
npm install koa-better-timeout
```

[yarn][]:

```sh
yarn add koa-better-timeout
```


## Usage

> Default middleware usage:

```js
const Timeout = require('koa-better-timeout');

// ...

const timeout = new Timeout();
app.use(timeout.middleware);
```

> Advanced middleware usage (e.g. using [Lad][] and its [@ladjs/i18n][ladjs-i18n] middleware) with translated response message:

```js
const Timeout = require('koa-better-timeout');

// ...

const timeout = new Timeout({
  message: ctx => ctx.translate('REQUEST_TIMED_OUT')
});
app.use(timeout.middleware);
```


## Options

You can optionally pass an object of options to `Timeout(opts)`.

The default option values use [Boom][] and are:

```js
{
  ms: 6000,
  message: Boom.clientTimeout().message,
  sendResponse: Boom.clientTimeout
}
```

Note that `message` can be a function that accepts one argument `ctx`.  This is useful if you wish to use i18n translation for the response message.


## Contributors

| Name           | Website                    |
| -------------- | -------------------------- |
| **Nick Baugh** | <http://niftylettuce.com/> |


## License

[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)


## 

[npm]: https://www.npmjs.com/

[yarn]: https://yarnpkg.com/

[lad]: https://lad.js.org

[boom]: https://github.com/hapijs/boom

[ladjs-i18n]: https://github.com/ladjs/i18n

[koa]: http://koajs.com/

---
_Source: https://npm.io/package/koa-better-timeout · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
