express-transaction-id
v1.0.0
Published
Express middleware to set a transaction id, unique identifier value that is attached to requests.
Downloads
43
Maintainers
Readme
express-transaction-id
Express middleware to set a transaction id, unique identifier value that is attached to requests.
Installation
npm install express-transaction-id --save
Usage
In an express based application:
const express = require('express');
const transactionId = require('express-transaction-id');
const app = express();
// Adding `express-transaction-id` middleware to generate transaction IDs
app.use(transactionId({ header: 'x-global-transaction-id' }));
app.get('/foo', (req, res, next) => {
return res.status(200).json({ transaction_id: req.getId() });
});
Options
| Option | Type | Default | Description |
| ------ |------|---------| ------------ |
| header | String | x-transaction-id
| The name of the inbound header to check for a transaction id. |
Methods
getId()
This methods is added to the incoming request by express-transaction-id
, and will allow you to get transaction_id
of current request.
req.getId(); // 1c204313-6526-4f36-b32f-a36a410c4ed8