You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@eropple/nestjs-correlation-id

Package Overview
Dependencies
2
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eropple/nestjs-correlation-id

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


Version published
Maintainers
1
Created

Readme

Source

@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.

FAQs

Package last updated on 29 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc