Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/floatdrop/express-request-id
Middleware for setting unique request id
https://github.com/floatdrop/express-request-id
Last synced: about 17 hours ago
JSON representation
Middleware for setting unique request id
- Host: GitHub
- URL: https://github.com/floatdrop/express-request-id
- Owner: floatdrop
- License: mit
- Created: 2014-07-02T07:14:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-12-28T15:44:06.000Z (about 1 year ago)
- Last Synced: 2024-12-28T11:07:46.559Z (8 days ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 121
- Watchers: 3
- Forks: 24
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# express-request-id
[![Tests](https://github.com/floatdrop/express-request-id/workflows/CI/badge.svg)](https://github.com/floatdrop/express-request-id/actions)
[![npm version](https://img.shields.io/npm/v/express-request-id.svg)](https://npmjs.org/package/express-request-id 'View this project on NPM')
[![npm downloads](https://img.shields.io/npm/dm/express-request-id)](https://www.npmjs.com/package/express-request-id)> Generates UUID for request and add it to header.
## Install
```sh
npm install express-request-id
```## Usage
```js
import express from 'express';
import requestID from 'express-request-id';app.use(requestID());
app.get('/', function (req, res, next) {
res.send(req.id);
next();
});app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});// curl localhost:3000
// d7c32387-3feb-452b-8df1-2d8338b3ea22
```## API
### requestID(options?)
#### options
Type: `object`
##### generator
Type: `function`
Default: `func(req) { return uuidv4(); }`Defines function, that generated ID from request. By default used `uuid` module, that generated UUID V4 for every request.
##### headerName
Type: `string`
Default: `X-Request-Id`Defines name of header, that should be used for request ID checking and setting.
##### setHeader
Type: `bool`
Default: `true`If `false` – header will not be set.