3.0.0 • Published 7 months ago
mnr-transaction-id v3.0.0
mnr-transaction-id
Express middleware for tracking transactions in microservices architecture.
You may not need it!
This is a custom, highly opinionated solution aimed at code reuse for a few private projects.
v3 Breaking Changes
From v3,
mnr-transaction-id
is an ESM-only module - you are not able to import it withrequire()
.Bump minimum supported version of Node.js to v20.
Archive documentation:
- v2;
Installation
$ npm install --save mnr-transaction-id
Usage Example
import mnrTransactionId, { RequestWithTransactionId } from 'mnr-transaction-id';
const app = express();
app.use(mnrTransactionId);
app.get('/my-endpoint', (req, res) => {
console.log((req as RequestWithTransactionId).transactionId);
});
What It Does
Add
req.transactionId
either from request'sx-transaction-id
HTTP header, or newly generated UUID if there is no such a header. The most obvious use case forreq.transactionId
is using it in logs.Add
x-transaction-id
HTTP header to response. The value is taken fromreq.transactionId
.