open-index/open-npm huggingface dataset:
npm package: @pas7/nestjs-request-context
Description: NestJS integration for request context management
Author: PAS7
Latest version: 0.3.8

# @pas7/nestjs-request-context

NestJS module and decorators for AsyncLocalStorage-based request context.

## Why use it

- Avoid request-scoped provider overhead
- Keep typed request metadata available in controllers/services
- Reuse one integration style for Express and Fastify adapters

## Installation

```bash
pnpm add @pas7/nestjs-request-context
```

You also need one adapter package:

```bash
pnpm add @pas7/nestjs-request-context-adapter-express
# or
pnpm add @pas7/nestjs-request-context-adapter-fastify
```

## Quick example

```ts
import { Module } from '@nestjs/common';
import { RequestContextModule } from '@pas7/nestjs-request-context';

@Module({
  imports: [RequestContextModule.forRoot({ mode: 'standard' })],
})
export class AppModule {}
```

```ts
import { Controller, Get } from '@nestjs/common';
import { Ctx, REQUEST_ID_KEY } from '@pas7/nestjs-request-context';

@Controller()
export class AppController {
  @Get()
  getRequestId(@Ctx(REQUEST_ID_KEY) requestId: string) {
    return { requestId };
  }
}
```

## Main exports

- `RequestContextModule`
- `RequestContextService`
- `Ctx`
- `ContextInterceptor`, `ContextGuard`
- `REQUEST_ID_KEY`, `ROUTE_KEY`, `METHOD_KEY`, `IP_KEY`
- `DEFAULT_HEADER`, `DEFAULT_KEYS`, `DEFAULT_MODE`

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- Core package: `@pas7/request-context-core`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0
npm package: @pas7/nestjs-request-context-adapter-express
Description: Express adapter for NestJS request context
Author: PAS7
Latest version: 0.3.8

# @pas7/nestjs-request-context-adapter-express

Express adapter for `@pas7/nestjs-request-context`.

## When to use

Use this package when your NestJS app runs on `@nestjs/platform-express`.

## Installation

```bash
pnpm add @pas7/nestjs-request-context @pas7/nestjs-request-context-adapter-express
```

## Quick example

```ts
import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
import { requestContextMiddleware } from '@pas7/nestjs-request-context-adapter-express';

@Module({})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(requestContextMiddleware())
      .forRoutes({ path: '*', method: RequestMethod.ALL });
  }
}
```

## Options

```ts
interface RequestContextExpressOptions {
  header?: string;
  idGenerator?: () => string;
  addResponseHeader?: boolean;
}
```

## Exports

- `requestContextMiddleware`
- `UseRequestContextExpress`
- `DEFAULT_EXPRESS_OPTIONS`
- `RequestContextExpressOptions`

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- Main package: `@pas7/nestjs-request-context`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0
npm package: @pas7/nestjs-request-context-adapter-fastify
Description: Fastify adapter for NestJS request context
Author: PAS7
Latest version: 0.3.8

# @pas7/nestjs-request-context-adapter-fastify

Fastify adapter for `@pas7/nestjs-request-context`.

## When to use

Use this package when your NestJS app runs on `@nestjs/platform-fastify`.

## Installation

```bash
pnpm add @pas7/nestjs-request-context @pas7/nestjs-request-context-adapter-fastify
```

## Quick example

```ts
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { requestContextMiddleware } from '@pas7/nestjs-request-context-adapter-fastify';

@Module({})
export class AppModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(requestContextMiddleware()).forRoutes('*');
  }
}
```

## Options

```ts
interface RequestContextFastifyOptions {
  header?: string;
  idGenerator?: () => string;
  addResponseHeader?: boolean;
}
```

## Exports

- `requestContextMiddleware`
- `requestContextPlugin`
- `UseRequestContextFastify`
- `DEFAULT_FASTIFY_OPTIONS`
- `RequestContextFastifyOptions`

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- Main package: `@pas7/nestjs-request-context`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0
npm package: @pas7/nestjs-request-context-shared
Description: Shared types and utilities for @pas7/nestjs-request-context adapters
Author: PAS7
Latest version: 0.3.8

# @pas7/nestjs-request-context-shared

Shared adapter types and interceptor factory for the request-context ecosystem.

## When to use

Usually you do not install this package directly. It is pulled in by adapter packages.

Install directly only if you are building your own adapter.

## Installation

```bash
pnpm add @pas7/nestjs-request-context-shared
```

## Main exports

- `RequestContextAdapterOptions`
- `DEFAULT_ADAPTER_OPTIONS`
- `createRequestContextInterceptor`
- `CreateInterceptorOptions`

## Quick custom-adapter example

```ts
import { createRequestContextInterceptor } from '@pas7/nestjs-request-context-shared';

const interceptor = createRequestContextInterceptor({
  options: { header: 'x-request-id' },
  getRequestId: (req, header) => req.headers[header],
  setRequestId: (res, header, id) => res.setHeader(header, id),
  getRequest: (ctx) => ctx.switchToHttp().getRequest(),
  getResponse: (ctx) => ctx.switchToHttp().getResponse(),
});
```

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- Express adapter: `@pas7/nestjs-request-context-adapter-express`
- Fastify adapter: `@pas7/nestjs-request-context-adapter-fastify`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0
npm package: @pas7/nestjs-request-context-testkit
Description: Testing utilities for NestJS request context
Author: PAS7
Latest version: 0.3.8

# @pas7/nestjs-request-context-testkit

Test utilities for validating request-context isolation and concurrency behavior.

## When to use

Use this package in integration/e2e tests to assert there is no context leak across parallel requests.

## Installation

```bash
pnpm add -D @pas7/nestjs-request-context-testkit
```

## Quick example

```ts
import {
  assertNoLeak,
  createTestAppFastify,
  runParallelRequests,
} from '@pas7/nestjs-request-context-testkit';

const testApp = await createTestAppFastify({
  module: { controllers: [TestController] },
});

const responses = await runParallelRequests(50, (i) =>
  request(testApp.app.getHttpServer()).get(`/test/${i}`).expect(200)
);

assertNoLeak(responses.map((r) => r.body));
```

## Exports

- `createTestAppFastify`
- `createTestAppExpress`
- `runParallelRequests`
- `assertNoLeak`
- `ContextLeakError`

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- Main package: `@pas7/nestjs-request-context`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0
npm package: @pas7/request-context-core
Description: Core request context management library
Author: PAS7
Latest version: 0.3.8

# @pas7/request-context-core

Framework-agnostic request context primitives built on AsyncLocalStorage.

## When to use

Use this package if you need request context outside NestJS abstractions, or when building custom integrations.

## Installation

```bash
pnpm add @pas7/request-context-core
```

## Quick example

```ts
import { ContextKey, get, run, set } from '@pas7/request-context-core';

const REQUEST_ID = new ContextKey<string>('requestId');

run({ requestId: 'req-1' }, () => {
  const id = get(REQUEST_ID);
  set(REQUEST_ID, `${id}-next`);
});
```

## Main API

- `Context`, `ContextKey`
- `run`, `get`, `set`, `has`, `require`, `merge`
- `snapshot`, `restore`
- `KeyExistsError`, `ContextMissingError`, `ContextNotActiveError`, `ContextKeyCollisionError`

## Related

- Root docs: `README.md`
- Changelog: `CHANGELOG.md`
- NestJS module: `@pas7/nestjs-request-context`

## About

Developed by **PAS7** - [https://pas7.com.ua/](https://pas7.com.ua/)

- 📖 Article: [NestJS Request Context with ALS](https://pas7.com.ua/blog/en/nestjs-request-context-als-2026)
- 📧 Contact: [https://pas7.com.ua/contact](https://pas7.com.ua/contact)

## License

Apache-2.0