{"_id":"@ashok92/correlation-id","name":"@ashok92/correlation-id","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@ashok92/correlation-id","version":"1.0.0","description":"Lightweight request-scoped correlation ID context for Node.js and Express using AsyncLocalStorage.","license":"MIT","author":{"name":"ashok92"},"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"},"./package.json":"./package.json"},"publishConfig":{"access":"public"},"packageManager":"npm@10","engines":{"node":">=18.0.0"},"sideEffects":false,"scripts":{"clean":"rimraf dist coverage","build":"tsup","dev":"tsup --watch","typecheck":"tsc --noEmit","lint":"eslint . --ext .ts","test":"vitest run --coverage","test:watch":"vitest","pack:check":"npm pack --dry-run","release:check":"npm run clean && npm run build && npm run test && npm run typecheck && npm pack --dry-run","publish:manual":"npm publish --access public","prepublishOnly":"npm run release:check"},"peerDependencies":{"express":">=4"},"peerDependenciesMeta":{"express":{"optional":true}},"devDependencies":{"@types/node":"^22.15.29","@types/express":"^5.0.5","@types/supertest":"^6.0.3","@typescript-eslint/eslint-plugin":"^8.39.1","@typescript-eslint/parser":"^8.39.1","@vitest/coverage-v8":"^3.2.4","eslint":"^8.57.1","express":"^5.1.0","prettier":"^3.6.2","rimraf":"^6.0.1","supertest":"^7.1.4","tsup":"^8.5.0","typescript":"^5.9.2","vitest":"^3.2.4"},"keywords":["correlation-id","request-context","async-local-storage","express","tracing","nodejs","typescript"],"_id":"@ashok92/correlation-id@1.0.0","_nodeVersion":"24.18.0","_npmVersion":"11.16.0","dist":{"integrity":"sha512-E+UKC0PI78h7Nyt0qWG1lMIu0bnk6m3Bj+LWbHB4QHYGMk7Q1iKl5w1YqczYs8S0CHZ/D8B478tr/1o7fwAQwg==","shasum":"3505792fc4580ca93dca8ebb1fb805e1728493e1","tarball":"https://registry.npmjs.org/@ashok92/correlation-id/-/correlation-id-1.0.0.tgz","fileCount":10,"unpackedSize":28957,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCID/PsZSeFDIApaClAw2iDAEHtKh/aHceku9l9EuahyoTAiEAwXPiL9pgVKA3GonfoCaNNaN6r8CmIHz+ri0n5Li1rdA="}]},"_npmUser":{"name":"ashok92","email":"ashoksethu92@gmail.com"},"directories":{},"maintainers":[{"name":"ashok92","email":"ashoksethu92@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/correlation-id_1.0.0_1785004288306_0.4915491574340414"},"_hasShrinkwrap":false}},"time":{"created":"2026-07-25T18:31:28.146Z","1.0.0":"2026-07-25T18:31:28.442Z","modified":"2026-07-25T18:31:28.611Z"},"maintainers":[{"name":"ashok92","email":"ashoksethu92@gmail.com"}],"description":"Lightweight request-scoped correlation ID context for Node.js and Express using AsyncLocalStorage.","keywords":["correlation-id","request-context","async-local-storage","express","tracing","nodejs","typescript"],"author":{"name":"ashok92"},"license":"MIT","readme":"# @ashok92/correlation-id\r\n\r\nLightweight request-scoped correlation ID context for Node.js and Express, powered by AsyncLocalStorage.\r\n\r\n## Why this package?\r\n\r\nIn distributed systems, one user request can touch many services. Correlation IDs let you trace all related logs and events for that request.\r\n\r\nThis package keeps the responsibility focused:\r\n\r\n- Create and propagate correlation IDs per request\r\n- Expose helpers to read and update the active request context\r\n- Stay logger-agnostic (works with Pino, Winston, Bunyan, console, etc.)\r\n\r\n## Features\r\n\r\n- AsyncLocalStorage-backed request context\r\n- Express middleware adapter\r\n- Reuse incoming `x-correlation-id` header\r\n- Generate ID if missing\r\n- Optional incoming UUID validation\r\n- Zero runtime dependencies\r\n- TypeScript-first API\r\n\r\n## Install\r\n\r\n```bash\r\nnpm install @ashok92/correlation-id\r\n```\r\n\r\n## Quick Start\r\n\r\n```ts\r\nimport express from \"express\";\r\nimport { correlationMiddleware, getCorrelationId } from \"@ashok92/correlation-id\";\r\n\r\nconst app = express();\r\n\r\napp.use(correlationMiddleware());\r\n\r\napp.get(\"/users\", (_req, res) => {\r\n  res.json({\r\n    message: \"ok\",\r\n    correlationId: getCorrelationId()\r\n  });\r\n});\r\n```\r\n\r\n## API\r\n\r\n- `correlationMiddleware(options?)`\r\n- `getCorrelationId()`\r\n- `hasCorrelationId()`\r\n- `setCorrelationId(correlationId)`\r\n- `getContext()`\r\n- `runWithContext(context, callback)`\r\n- `generateCorrelationId()`\r\n- `isValidCorrelationId(value)`\r\n\r\n## Middleware Options\r\n\r\n```ts\r\ninterface CorrelationMiddlewareOptions {\r\n  headerName?: string; // default: x-correlation-id\r\n  generateIfMissing?: boolean; // default: true\r\n  responseHeader?: boolean; // default: true\r\n  validateIncoming?: boolean; // default: false\r\n}\r\n```\r\n\r\n## Local Development\r\n\r\n```bash\r\nnpm install\r\nnpm run lint\r\nnpm run test\r\nnpm run build\r\n```\r\n\r\n## Publish Checklist\r\n\r\n```bash\r\nnpm run release:check\r\nnpm whoami\r\nnpm publish --access public\r\n```\r\n\r\nRecommended before publish:\r\n\r\n- Enable npm account 2FA for publish and settings changes\r\n- Ensure version is bumped (never republish same version)\r\n- Verify package content with `npm pack --dry-run`\r\n- Confirm sensitive files are excluded (only `files` whitelist is published)\r\n\r\n## License\r\n\r\nMIT","readmeFilename":"README.md","_rev":"1-cfacc77d3e119b7e9d12d7a467ee334f"}