@eropple/nestjs-correlation-id

中文文档
1.0.1发布于 2019/05/29MITCommonJS近 30 天下载 2785

Middleware for managing X-Correlation-Id headers in NestJS (or any other Express app).

此软件包已被标记为弃用

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

原始使用文档

@eropple/nestjs-correlation-id

This package contains a single global middleware that operates on the X-Correlation-Id header. If it doesn't exist on the incoming request, it generates a random UUID and attaches it to the X-Correlation-Id header on the request (http.IncomingMessage) and the response (http.ServerResponse) objects within the NestJS request pipeline. If it already exists, the existing value is copied to the response's headers.

Unlike other packages that do the same thing, this doesn't allow you to change the header name. That's because other packages in my @eropple/nestjs-* ecosystem rely on X-Correlation-Id and this is intended to be used in conjunction with them.. If you're not going to go use @eropple/nestjs-data-sec or @eropple/nestjs-auth, you probably don't care - but almost everybody uses X-Correlation-Id or X-Request-Id, so this still may work for you.

This is tested with Express; as it's a middleware it probably won't work with Fastify. If somebody wants to add a Fastify version, pull requests are gratefully accepted.

Installation

yarn install @eropple/nestjs-correlation-id

Usage

Add this as the first middleware in your global middleware chain. (That way, anything that comes after it--like, )

import { CorrelationIdMiddleware } from "@eropple/nestjs-correlation-id";

async function init() {
  const app: INestApplication = /* ... */

  app.use(CorrelationIdMiddleware());
  /* add other middleware, interceptors, etc. */

  await app.listen(3000);
}

By default, this uses uuid/v4 to generate a value, but you can do whatever you want by passing a () => string function to it. UUIDs tend to be the most common option, though.

版本与发布记录

@eropple/nestjs-correlation-id 共发布 2 个版本,首次发布于 2019/05/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.1latest2019/05/297 年前
1.0.02019/05/217 年前

关于 @eropple/nestjs-correlation-id 的常见问题

@eropple/nestjs-correlation-id 是什么?

Middleware for managing X-Correlation-Id headers in NestJS (or any other Express app).注意:该包已被作者标记为弃用——Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

如何安装 @eropple/nestjs-correlation-id?

在项目目录运行 npm install @eropple/nestjs-correlation-id,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(>=6.4.0)、@nestjs/common(>=6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@eropple/nestjs-correlation-id 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/eropple__nestjs-correlation-id 是否存在。

@eropple/nestjs-correlation-id 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@eropple/nestjs-correlation-id 可以商用吗?

@eropple/nestjs-correlation-id 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eropple/nestjs-correlation-id 的下载量有多少?

根据 npm 官方下载统计,@eropple/nestjs-correlation-id 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,785 次,日均约 93 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eropple/nestjs-correlation-id 还在维护吗?

最新版本 1.0.1 发布于 2019/05/29(7 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/05/21。作者已将其标记为弃用,新项目建议寻找替代方案。