correlationid-middleware
raw JSON → 0.0.2 verified Sat Apr 25 auth: no javascript
A middleware package for automatically generating and propagating correlation IDs across HTTP requests and responses. Current stable version is 0.0.2, with an unclear release cadence. It differentiates itself by offering a minimal, zero-dependency approach for Node.js applications using Express or similar frameworks. However, the package is very early-stage (pre-1.0), poorly documented, and may not support ESM or TypeScript natively. It is a niche tool for developers needing lightweight correlation ID tracking without external services.
Common errors
error Cannot find module 'correlationid-middleware' ↓
cause Package not installed or not in node_modules.
fix
Run 'npm install correlationid-middleware' and ensure package.json lists it.
error correlationId is not a function ↓
cause Import returns object instead of function.
fix
Check actual exports: use require('correlationid-middleware') and log the module.
Warnings
gotcha No README or documentation; API usage is ambiguous. ↓
fix Inspect source code to understand exports and config options.
deprecated Version 0.0.2 is extremely early; no stability guarantees. ↓
fix Consider mature alternatives like 'correlation-id' or 'express-correlation-id'.
gotcha Default export behavior may change without prior notice. ↓
fix Stick to known working version and pin dependency.
Install
npm install correlationid-middleware yarn add correlationid-middleware pnpm add correlationid-middleware Imports
- default wrong
const correlationId = require('correlationid-middleware')correctimport correlationId from 'correlationid-middleware' - CorrelationIdMiddleware wrong
import { CorrelationIdMiddleware } from 'correlationid-middleware'correctconst { CorrelationIdMiddleware } = require('correlationid-middleware') - Types
import type { CorrelationIdOptions } from 'correlationid-middleware'
Quickstart
const express = require('express');
const correlationId = require('correlationid-middleware');
const app = express();
app.use(correlationId());
app.get('/', (req, res) => {
console.log(req.correlationId);
res.json({ correlationId: req.correlationId });
});
app.listen(3000, () => console.log('Server running on port 3000'));