# request-id

> Allows you to identify client requests within non-sequential logs such as Syslog by adding a response header of `X-Request-Id`. Allows setting value via query parameter or request header. For Koa and Express.

Latest version **0.11.1** (published 2016-12-26) · MIT license · 0 weekly downloads

## Install

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

## 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.11.1 |
| Published | 2016-12-26 |
| First published | 2014-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Wil Moore III |
| Maintainers | wilmoore |
| Keywords | ecosystem:express, ecosystem:koa, express, header, http, koa, middleware, request-id, syslog, x-request-id |

## Links

- npm: https://www.npmjs.com/package/request-id
- Repository: https://github.com/wilmoore/request-id.js
- Issues: https://github.com/wilmoore/request-id.js/issues
- npm.io page: https://npm.io/package/request-id

## Dependencies (1)

- [uuid](https://npm.io/package/uuid.md) ^3.0.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.11.1 (latest) — 2016-12-26
- 0.11.0 — 2016-04-11
- 0.10.0 — 2015-08-03
- 0.9.0 — 2014-11-14
- 0.8.0 — 2014-11-05
- 0.7.0 — 2014-11-05
- 0.6.0 — 2014-10-15
- 0.4.0 — 2014-10-14
- 0.3.0 — 2014-10-14
- 0.2.0 — 2014-10-14

## README

# request-id

[![Build Status](http://img.shields.io/travis/wilmoore/request-id.js.svg)](https://travis-ci.org/wilmoore/request-id.js) [![NPM version](http://img.shields.io/npm/v/request-id.svg)](https://www.npmjs.org/package/request-id) [![NPM downloads](http://img.shields.io/npm/dm/request-id.svg)](https://www.npmjs.org/package/request-id) [![LICENSE](http://img.shields.io/npm/l/request-id.svg)](license)

> Allows you to identify client requests within non-sequential logs such as Syslog by adding a response header of `X-Request-Id`. Allows setting value via query parameter or request header. For Koa and Express.

    $ npm install request-id

## Usage

###### Quick Start (koa or express)

    # koa
    var requestId = require('request-id');
    var app = require('koa')();
    app.use(requestId());

    # express
    var requestId = require('request-id/express');
    var app = require('express')();
    app.use(requestId());

###### Random ID

    % curl example.com
    //=> X-Client-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

###### Set ID via request header

    % curl -H 'X-Request-ID:a37cacc3-71d5-40f0-a329-a051a3949ced' example.com
    //=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

###### Set ID via query param

    % curl example.com?requestId=a37cacc3-71d5-40f0-a329-a051a3949ced
    //=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

## Options

###### Custom Response Header (default: `X-Request-Id`)

    app.use(requestId({
      resHeader: 'X-Client-ID'
    }));

    % curl example.com
    //=> X-Client-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

###### Custom Request Header (default: `X-Request-Id`)

> Keep in mind that changing the request header does not have any effect on the default response header. If you want them to match, you'll need to set both `.resHeader` and `.reqHeader`.

    app.use(requestId({
      reqHeader: 'X-Client-ID'
    }));

    % curl -H 'X-Client-ID:a37cacc3-71d5-40f0-a329-a051a3949ced' example.com
    //=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

###### Custom Query Parameter (default: `requestId`)

    app.use(requestId({
      paramName: 'requestId'
    }));

    % curl example.com?requestId=a37cacc3-71d5-40f0-a329-a051a3949ced
    //=> X-Request-ID: a37cacc3-71d5-40f0-a329-a051a3949ced

###### Custom Value Generator Function (default: [node-uuid.v4])

    app.use(requestId({
      generator: function () { return 'ABC'; }
    }));

    % curl example.com
    //=> X-Request-ID: ABC

## Alternatives

- [connect-rid]
- [connect-request-id]
- [connect-requestid]
- [express-request-id]
- [koa-request-id]
- [request-id-middleware]

## License

  [MIT](license)

[connect-rid]:            https://www.npmjs.org/package/connect-rid
[node-uuid.v4]:           https://github.com/broofa/node-uuid#uuidv4options--buffer--offset
[koa-request-id]:         https://www.npmjs.org/package/koa-request-id
[express-request-id]:     https://www.npmjs.org/package/express-request-id
[connect-request-id]:     https://www.npmjs.org/package/connect-request-id
[request-id-middleware]:  https://www.npmjs.org/package/request-id-middleware
[connect-requestid]:      https://www.npmjs.org/package/connect-requestid

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