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
| Method | Signature | Returns |
|---|---|---|
setGlobalPrefix | setGlobalPrefix(prefix: string) | void |
getGlobalPrefix | getGlobalPrefix() | void |
setGlobalPrefixOptions | setGlobalPrefixOptions(options: GlobalPrefixOptions<ExcludeRouteMetadata>) | void |
getGlobalPrefixOptions | getGlobalPrefixOptions() | GlobalPrefixOptions<ExcludeRouteMetadata> |
setIoAdapter | setIoAdapter(ioAdapter: WebSocketAdapter) | void |
getIoAdapter | getIoAdapter() | WebSocketAdapter |
addGlobalPipe | addGlobalPipe(pipe: PipeTransform<any>) | void |
useGlobalPipes | useGlobalPipes(pipes: PipeTransform<any>[]) | void |
getGlobalFilters | getGlobalFilters() | ExceptionFilter[] |
addGlobalFilter | addGlobalFilter(filter: ExceptionFilter) | void |
useGlobalFilters | useGlobalFilters(filters: ExceptionFilter[]) | void |
getGlobalPipes | getGlobalPipes() | PipeTransform<any>[] |
getGlobalInterceptors | getGlobalInterceptors() | NestInterceptor[] |
addGlobalInterceptor | addGlobalInterceptor(interceptor: NestInterceptor) | void |
useGlobalInterceptors | useGlobalInterceptors(interceptors: NestInterceptor[]) | void |
getGlobalGuards | getGlobalGuards() | CanActivate[] |
addGlobalGuard | addGlobalGuard(guard: CanActivate) | void |
useGlobalGuards | useGlobalGuards(guards: CanActivate[]) | void |
addGlobalRequestInterceptor | addGlobalRequestInterceptor(wrapper: InstanceWrapper<NestInterceptor>) | void |
getGlobalRequestInterceptors | getGlobalRequestInterceptors() | InstanceWrapper<NestInterceptor>[] |
addGlobalRequestPipe | addGlobalRequestPipe(wrapper: InstanceWrapper<PipeTransform>) | void |
getGlobalRequestPipes | getGlobalRequestPipes() | InstanceWrapper<PipeTransform>[] |
addGlobalRequestFilter | addGlobalRequestFilter(wrapper: InstanceWrapper<ExceptionFilter>) | void |
getGlobalRequestFilters | getGlobalRequestFilters() | InstanceWrapper<ExceptionFilter>[] |
addGlobalRequestGuard | addGlobalRequestGuard(wrapper: InstanceWrapper<CanActivate>) | void |
getGlobalRequestGuards | getGlobalRequestGuards() | InstanceWrapper<CanActivate>[] |
enableVersioning | enableVersioning(options: VersioningOptions) | void |
getVersioning | getVersioning() | `VersioningOptions |
Diagram
mermaidgraph 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
tsimport { 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()andsetGlobalPrefixOptions()together when routes need a shared prefix with explicit exclusions. - Prefer
useGlobalPipes(...pipes)when registering multiple pipes at once; useaddGlobalPipe()for incremental registration. - Ensure global pipes and filters are registered during application setup, before handling requests or initializing gateways.
- Provide a valid
WebSocketAdapterimplementation throughsetIoAdapter()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)
ExceptionFiltersContext—packages/microservices/context/exception-filters-context.ts:16MicroservicesModule—packages/microservices/microservices-module.ts:23NestMicroservice—packages/microservices/nest-microservice.ts:35TestingModuleOptions—packages/testing/testing-module.builder.ts:29TestingModule—packages/testing/testing-module.ts:26SocketModule—packages/websockets/socket-module.ts:27SocketServerProvider—packages/websockets/socket-server-provider.ts:8WebSocketsController—packages/websockets/web-sockets-controller.ts:29
Was this page helpful?