Skip to content

ApplicationConfig

reference
1 min readUpdated

Kind: Class

Source: packages/core/application-config.ts

Part of: Core

ApplicationConfig stores application-wide runtime configuration used by the NestJS application bootstrap process. It manages global HTTP prefix settings, WebSocket adapters, pipes, and exception filters so these concerns can be applied consistently across the application.

Methods

MethodSignatureReturns
setGlobalPrefixsetGlobalPrefix(prefix: string)void
getGlobalPrefixgetGlobalPrefix()void
setGlobalPrefixOptionssetGlobalPrefixOptions(options: GlobalPrefixOptions<ExcludeRouteMetadata>)void
getGlobalPrefixOptionsgetGlobalPrefixOptions()GlobalPrefixOptions<ExcludeRouteMetadata>
setIoAdaptersetIoAdapter(ioAdapter: WebSocketAdapter)void
getIoAdaptergetIoAdapter()WebSocketAdapter
addGlobalPipeaddGlobalPipe(pipe: PipeTransform<any>)void
useGlobalPipesuseGlobalPipes(pipes: PipeTransform<any>[])void
getGlobalFiltersgetGlobalFilters()ExceptionFilter[]
addGlobalFilteraddGlobalFilter(filter: ExceptionFilter)void
useGlobalFiltersuseGlobalFilters(filters: ExceptionFilter[])void
getGlobalPipesgetGlobalPipes()PipeTransform<any>[]
getGlobalInterceptorsgetGlobalInterceptors()NestInterceptor[]
addGlobalInterceptoraddGlobalInterceptor(interceptor: NestInterceptor)void
useGlobalInterceptorsuseGlobalInterceptors(interceptors: NestInterceptor[])void
getGlobalGuardsgetGlobalGuards()CanActivate[]
addGlobalGuardaddGlobalGuard(guard: CanActivate)void
useGlobalGuardsuseGlobalGuards(guards: CanActivate[])void
addGlobalRequestInterceptoraddGlobalRequestInterceptor(wrapper: InstanceWrapper<NestInterceptor>)void
getGlobalRequestInterceptorsgetGlobalRequestInterceptors()InstanceWrapper<NestInterceptor>[]
addGlobalRequestPipeaddGlobalRequestPipe(wrapper: InstanceWrapper<PipeTransform>)void
getGlobalRequestPipesgetGlobalRequestPipes()InstanceWrapper<PipeTransform>[]
addGlobalRequestFilteraddGlobalRequestFilter(wrapper: InstanceWrapper<ExceptionFilter>)void
getGlobalRequestFiltersgetGlobalRequestFilters()InstanceWrapper<ExceptionFilter>[]
addGlobalRequestGuardaddGlobalRequestGuard(wrapper: InstanceWrapper<CanActivate>)void
getGlobalRequestGuardsgetGlobalRequestGuards()InstanceWrapper<CanActivate>[]
enableVersioningenableVersioning(options: VersioningOptions)void
getVersioninggetVersioning()`VersioningOptions

Diagram

mermaid
graph LR
  App[Nest Application] --> Config[ApplicationConfig]

  Config --> Prefix[Global Prefix]
  Config --> PrefixOptions[Prefix Exclusion Options]
  Config --> IoAdapter[WebSocket Adapter]
  Config --> Pipes[Global Pipes]
  Config --> Filters[Global Exception Filters]

  Prefix --> Routes[HTTP Routes]
  IoAdapter --> Gateways[WebSocket Gateways]
  Pipes --> Requests[Incoming Requests]
  Filters --> Errors[Unhandled Exceptions]

Usage

ts
import { RequestMethod, ValidationPipe } from '@nestjs/common';
import { ApplicationConfig } from '@nestjs/core/application-config';
import { WsAdapter } from '@nestjs/platform-ws';

const config = new ApplicationConfig();

// Configure HTTP route prefixing.
config.setGlobalPrefix('api');
config.setGlobalPrefixOptions({
  exclude: [{ path: 'health', method: RequestMethod.GET }],
});

// Apply request validation globally.
config.addGlobalPipe(
  new ValidationPipe({
    transform: true,
    whitelist: true,
  }),
);

// Configure the WebSocket transport adapter.
config.setIoAdapter(new WsAdapter());

// Inspect configured values when integrating with application bootstrap.
console.log(config.getGlobalPrefix()); // "api"
console.log(config.getIoAdapter());
console.log(config.getGlobalFilters());

AI Coding Instructions

  • Use setGlobalPrefix() and setGlobalPrefixOptions() together when routes need a shared prefix with explicit exclusions.
  • Prefer useGlobalPipes(...pipes) when registering multiple pipes at once; use addGlobalPipe() for incremental registration.
  • Ensure global pipes and filters are registered during application setup, before handling requests or initializing gateways.
  • Provide a valid WebSocketAdapter implementation through setIoAdapter() before starting WebSocket gateway infrastructure.
  • Treat values returned by getters as application-wide configuration state; avoid mutating returned collections directly.

Relationships

  • IMPORTS → CanActivate
  • IMPORTS → ExceptionFilter
  • IMPORTS → NestInterceptor
  • IMPORTS → PipeTransform
  • IMPORTS → VersioningOptions
  • IMPORTS → WebSocketAdapter
  • IMPORTS → GlobalPrefixOptions

Used by

8 references from 8 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (8)

  • ExceptionFiltersContextpackages/microservices/context/exception-filters-context.ts:16
  • MicroservicesModulepackages/microservices/microservices-module.ts:23
  • NestMicroservicepackages/microservices/nest-microservice.ts:35
  • TestingModuleOptionspackages/testing/testing-module.builder.ts:29
  • TestingModulepackages/testing/testing-module.ts:26
  • SocketModulepackages/websockets/socket-module.ts:27
  • SocketServerProviderpackages/websockets/socket-server-provider.ts:8
  • WebSocketsControllerpackages/websockets/web-sockets-controller.ts:29

Was this page helpful?

Download as PDF
ApplicationConfig — NestJS head-to-head