# request-received

> Route middleware for Koa and Express that adds a request received high-resolution timer and Date to the request object using easily accessible Symbols to prevent request object pollution. Made for Cabin.

Latest version **0.0.3** (published 2019-09-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install request-received
pnpm add request-received
yarn add request-received
bun add request-received
```

## 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.3 |
| Published | 2019-09-18 |
| First published | 2019-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.4.0 |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Nick Baugh |
| Maintainers | niftylettuce |
| Keywords | Symbol, airbrake, bunyan, cabin, connect, date, diff, difference, express, for, high, hrtime, http, koa, log, logger, logging, loggly, morgan, morgan, ms, pino, process, process.hrtime, received, request, resolution, sentry, service, signale, start, started, timber, time, timer, timestamp, timing, tool, utility, winston, x-response-time |

## Links

- npm: https://www.npmjs.com/package/request-received
- Repository: https://github.com/cabinjs/request-received
- Issues: https://github.com/cabinjs/request-received/issues
- npm.io page: https://npm.io/package/request-received

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-09-18
- 0.0.2 — 2019-06-14
- 0.0.1 — 2019-06-13

## README

# request-received

[![build status](https://img.shields.io/travis/com/cabinjs/request-received.svg)](https://travis-ci.com/cabinjs/request-received)
[![code coverage](https://img.shields.io/codecov/c/github/cabinjs/request-received.svg)](https://codecov.io/gh/cabinjs/request-received)
[![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/cabinjs/request-received.svg)](LICENSE)
[![npm downloads](https://img.shields.io/npm/dt/request-received.svg)](https://npm.im/request-received)

> Route middleware for Koa and Express that adds a request received high-resolution timer and Date to the request object using easily accessible Symbols to prevent request object pollution.  Made for [Cabin][].


## Table of Contents

* [Install](#install)
* [Usage](#usage)
  * [Express](#express)
  * [Koa](#koa)
* [Contributors](#contributors)
* [License](#license)


## Install

[npm][]:

```sh
npm install request-received
```

[yarn][]:

```sh
yarn add request-received
```


## Usage

### Express

> Symbols are automatically added to `req` object in route middleware:

```js
const express = require('express');
const Cabin = require('cabin');
const requestReceived = require('request-received');
const responseTime = require('response-time');
const requestId = require('express-request-id');

const startAt = Symbol.for('request-received.startAt');
const startTime = Symbol.for('request-received.startTime');

const app = express();
const Cabin = new Cabin();

app.use(requestReceived);

app.use((req, res, next) => {
  console.log('startAt', req[startAt]); // `process.hrtime()`
  // [ 472542, 431456521 ]
  console.log('startTime', req[startTime]); // Date.now()
  // 1560499520000
  next();
});

app.use(responseTime());
app.use(requestId());
app.use(cabin.middleware);

app.listen();
```

### Koa

> Symbols are automatically added to `ctx`, `ctx.req`, and `ctx.request` objects in route middleware:

```js
const Koa = require('koa');
const koaConnect = require('koa-connect');
const responseReceived = require('response-received');
const responseTime = require('response-time');
const requestId = require('express-request-id');

const startAt = Symbol.for('request-received.startAt');
const startTime = Symbol.for('request-received.startTime');

const app = new Koa();
const Cabin = new Cabin();

app.use(requestReceived);

app.use((ctx, next) => {
  console.log('startAt', ctx[startAt]); // `process.hrtime()`
  // [ 472542, 431456521 ]
  console.log('startTime', ctx[startTime]); // Date.now()
  // 1560499520000

  // note that the symbols are also accessible via:
  // ctx.req[startAt]
  // ctx.request[startAt]
  // ctx.req[startTime]
  // ctx.request[startTime]

  return next();
});

app.use(koaConnect(responseTime));
app.use(requestId());
app.use(cabin.middleware);

app.listen();
```


## 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/

[cabin]: https://cabinjs.com

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