Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eropple/nestjs-correlation-id

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

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

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
929
decreased by-25.08%
Maintainers
1
Weekly downloads
 
Created
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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc