@nestjs/core
- Version 10.2.10
- Published
- 522 kB
- 6 dependencies
- MIT license
Install
npm i @nestjs/core
yarn add @nestjs/core
pnpm add @nestjs/core
Overview
Nest - modern, fast, powerful node.js web framework (@core)
Index
Variables
Functions
Classes
AbstractHttpAdapter
- all()
- applyVersionFilter()
- close()
- createMiddlewareFactory()
- delete()
- enableCors()
- end()
- get()
- getHttpServer()
- getInstance()
- getRequestHostname()
- getRequestMethod()
- getRequestUrl()
- getType()
- head()
- httpServer
- init()
- initHttpServer()
- instance
- isHeadersSent()
- listen()
- options()
- patch()
- post()
- put()
- redirect()
- registerParserMiddleware()
- render()
- reply()
- search()
- setErrorHandler()
- setHeader()
- setHttpServer()
- setInstance()
- setNotFoundHandler()
- setViewEngine()
- status()
- use()
- useStaticAssets()
ApplicationConfig
- addGlobalFilter()
- addGlobalGuard()
- addGlobalInterceptor()
- addGlobalPipe()
- addGlobalRequestFilter()
- addGlobalRequestGuard()
- addGlobalRequestInterceptor()
- addGlobalRequestPipe()
- enableVersioning()
- getGlobalFilters()
- getGlobalGuards()
- getGlobalInterceptors()
- getGlobalPipes()
- getGlobalPrefix()
- getGlobalPrefixOptions()
- getGlobalRequestFilters()
- getGlobalRequestGuards()
- getGlobalRequestInterceptors()
- getGlobalRequestPipes()
- getIoAdapter()
- getVersioning()
- setGlobalPrefix()
- setGlobalPrefixOptions()
- setIoAdapter()
- useGlobalFilters()
- useGlobalGuards()
- useGlobalInterceptors()
- useGlobalPipes()
NestApplication
- applyOptions()
- connectMicroservice()
- createServer()
- dispose()
- enableCors()
- enableVersioning()
- getHttpAdapter()
- getHttpServer()
- getMicroservices()
- getUnderlyingHttpServer()
- getUrl()
- init()
- listen()
- logger
- registerHttpServer()
- registerModules()
- registerParserMiddleware()
- registerRouter()
- registerRouterHooks()
- registerWsModule()
- setBaseViewsDir()
- setGlobalPrefix()
- setViewEngine()
- startAllMicroservices()
- use()
- useBodyParser()
- useGlobalFilters()
- useGlobalGuards()
- useGlobalInterceptors()
- useGlobalPipes()
- useStaticAssets()
- useWebSocketAdapter()
NestApplicationContext
- appOptions
- assertNotInPreviewMode()
- callBeforeShutdownHook()
- callBootstrapHook()
- callDestroyHook()
- callInitHook()
- callShutdownHook()
- close()
- container
- dispose()
- enableShutdownHooks()
- flushLogs()
- flushLogsOnOverride()
- get()
- init()
- injector
- instanceLinksHost
- isInitialized
- listenToShutdownSignals()
- logger
- registerRequestByContextId()
- resolve()
- select()
- selectContextModule()
- unsubscribeFromProcessSignals()
- useLogger()
NestContainer
- addController()
- addDynamicMetadata()
- addDynamicModules()
- addExportedProvider()
- addGlobalModule()
- addImport()
- addInjectable()
- addModule()
- addProvider()
- applicationConfig
- bindGlobalModuleToModule()
- bindGlobalScope()
- bindGlobalsToImports()
- clear()
- getDynamicMetadataByToken()
- getHttpAdapterHostRef()
- getHttpAdapterRef()
- getInternalCoreModuleRef()
- getModuleByKey()
- getModuleCompiler()
- getModules()
- getModuleTokenFactory()
- isGlobalModule()
- registerCoreModuleRef()
- registerRequestProvider()
- replace()
- replaceModule()
- serializedGraph
- setHttpAdapter()
Interfaces
Type Aliases
Variables
variable APP_FILTER
const APP_FILTER: string;
variable APP_GUARD
const APP_GUARD: string;
variable APP_INTERCEPTOR
const APP_INTERCEPTOR: string;
variable APP_PIPE
const APP_PIPE: string;
variable INQUIRER
const INQUIRER: string;
variable NestFactory
const NestFactory: NestFactoryStatic;
Use NestFactory to create an application instance.
### Specifying an entry module
Pass the required *root module* for the application via the module parameter. By convention, it is usually called
ApplicationModule
. Starting with this module, Nest assembles the dependency graph and begins the process of Dependency Injection and instantiates the classes needed to launch your application.
variable REQUEST
const REQUEST: string;
Functions
function createContextId
createContextId: () => ContextId;
function repl
repl: (module: Type | DynamicModule) => Promise<import('repl').REPLServer>;
Classes
class AbstractHttpAdapter
abstract class AbstractHttpAdapter<TServer = any, TRequest = any, TResponse = any> implements HttpServer<TRequest, TResponse> {}
constructor
constructor(instance?: any);
property httpServer
protected httpServer: {};
property instance
protected instance?: any;
method all
all: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method applyVersionFilter
abstract applyVersionFilter: ( handler: Function, version: VersionValue, versioningOptions: VersioningOptions) => (req: TRequest, res: TResponse, next: () => void) => Function;
method close
abstract close: () => any;
method createMiddlewareFactory
abstract createMiddlewareFactory: ( requestMethod: RequestMethod) => | ((path: string, callback: Function) => any) | Promise<(path: string, callback: Function) => any>;
method delete
delete: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method enableCors
abstract enableCors: ( options: CorsOptions | CorsOptionsDelegate<TRequest>, prefix?: string) => any;
method end
abstract end: (response: any, message?: string) => any;
method get
get: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method getHttpServer
getHttpServer: () => TServer;
method getInstance
getInstance: <T = any>() => T;
method getRequestHostname
abstract getRequestHostname: (request: any) => any;
method getRequestMethod
abstract getRequestMethod: (request: any) => any;
method getRequestUrl
abstract getRequestUrl: (request: any) => any;
method getType
abstract getType: () => string;
method head
head: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method init
init: () => Promise<void>;
method initHttpServer
abstract initHttpServer: (options: NestApplicationOptions) => any;
method isHeadersSent
abstract isHeadersSent: (response: any) => any;
method listen
listen: { (port: string | number, callback?: () => void): any; (port: string | number, hostname: string, callback?: () => void): any;};
method options
options: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method patch
patch: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method post
post: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method put
put: { (handler: RequestHandler): any; (path: any, handler: RequestHandler): any;};
method redirect
abstract redirect: (response: any, statusCode: number, url: string) => any;
method registerParserMiddleware
abstract registerParserMiddleware: (prefix?: string, rawBody?: boolean) => any;
method render
abstract render: (response: any, view: string, options: any) => any;
method reply
abstract reply: (response: any, body: any, statusCode?: number) => any;
method search
search: { (port: string | number, callback?: () => void): any; (port: string | number, hostname: string, callback?: () => void): any;};
method setErrorHandler
abstract setErrorHandler: (handler: Function, prefix?: string) => any;
method setHeader
abstract setHeader: (response: any, name: string, value: string) => any;
method setHttpServer
setHttpServer: (httpServer: TServer) => void;
method setInstance
setInstance: <T = any>(instance: T) => void;
method setNotFoundHandler
abstract setNotFoundHandler: (handler: Function, prefix?: string) => any;
method setViewEngine
abstract setViewEngine: (engine: string) => any;
method status
abstract status: (response: any, statusCode: number) => any;
method use
use: (...args: any[]) => any;
method useStaticAssets
abstract useStaticAssets: (...args: any[]) => any;
class ApplicationConfig
class ApplicationConfig {}
constructor
constructor(ioAdapter?: any);
method addGlobalFilter
addGlobalFilter: (filter: ExceptionFilter) => void;
method addGlobalGuard
addGlobalGuard: (guard: CanActivate) => void;
method addGlobalInterceptor
addGlobalInterceptor: (interceptor: NestInterceptor) => void;
method addGlobalPipe
addGlobalPipe: (pipe: PipeTransform<any>) => void;
method addGlobalRequestFilter
addGlobalRequestFilter: (wrapper: InstanceWrapper<ExceptionFilter>) => void;
method addGlobalRequestGuard
addGlobalRequestGuard: (wrapper: InstanceWrapper<CanActivate>) => void;
method addGlobalRequestInterceptor
addGlobalRequestInterceptor: (wrapper: InstanceWrapper<NestInterceptor>) => void;
method addGlobalRequestPipe
addGlobalRequestPipe: (wrapper: InstanceWrapper<PipeTransform>) => void;
method enableVersioning
enableVersioning: (options: VersioningOptions) => void;
method getGlobalFilters
getGlobalFilters: () => ExceptionFilter[];
method getGlobalGuards
getGlobalGuards: () => CanActivate[];
method getGlobalInterceptors
getGlobalInterceptors: () => NestInterceptor[];
method getGlobalPipes
getGlobalPipes: () => PipeTransform<any>[];
method getGlobalPrefix
getGlobalPrefix: () => string;
method getGlobalPrefixOptions
getGlobalPrefixOptions: () => GlobalPrefixOptions<ExcludeRouteMetadata>;
method getGlobalRequestFilters
getGlobalRequestFilters: () => InstanceWrapper<ExceptionFilter>[];
method getGlobalRequestGuards
getGlobalRequestGuards: () => InstanceWrapper<CanActivate>[];
method getGlobalRequestInterceptors
getGlobalRequestInterceptors: () => InstanceWrapper<NestInterceptor>[];
method getGlobalRequestPipes
getGlobalRequestPipes: () => InstanceWrapper<PipeTransform>[];
method getIoAdapter
getIoAdapter: () => WebSocketAdapter;
method getVersioning
getVersioning: () => VersioningOptions | undefined;
method setGlobalPrefix
setGlobalPrefix: (prefix: string) => void;
method setGlobalPrefixOptions
setGlobalPrefixOptions: ( options: GlobalPrefixOptions<ExcludeRouteMetadata>) => void;
method setIoAdapter
setIoAdapter: (ioAdapter: WebSocketAdapter) => void;
method useGlobalFilters
useGlobalFilters: (...filters: ExceptionFilter[]) => void;
method useGlobalGuards
useGlobalGuards: (...guards: CanActivate[]) => void;
method useGlobalInterceptors
useGlobalInterceptors: (...interceptors: NestInterceptor[]) => void;
method useGlobalPipes
useGlobalPipes: (...pipes: PipeTransform<any>[]) => void;
class BaseExceptionFilter
class BaseExceptionFilter<T = any> implements ExceptionFilter<T> {}
constructor
constructor(applicationRef?: HttpServer);
property applicationRef
protected readonly applicationRef?: HttpServer;
property httpAdapterHost
protected readonly httpAdapterHost?: HttpAdapterHost< AbstractHttpAdapter<any, any, any>>;
method catch
catch: (exception: T, host: ArgumentsHost) => void;
method handleUnknownError
handleUnknownError: ( exception: T, host: ArgumentsHost, applicationRef: AbstractHttpAdapter | HttpServer) => void;
method isExceptionObject
isExceptionObject: (err: any) => err is Error;
method isHttpError
isHttpError: (err: any) => err is { statusCode: number; message: string };
Checks if the thrown error comes from the "http-errors" library.
Parameter err
error object
class ContextIdFactory
class ContextIdFactory {}
method apply
static apply: (strategy: ContextIdStrategy) => void;
Registers a custom context id strategy that lets you attach a parent context id to the existing context id object.
Parameter strategy
strategy instance
method create
static create: () => ContextId;
Generates a context identifier based on the request object.
method getByRequest
static getByRequest: <T extends Record<any, any> = any>( request: T, propsToInspect?: string[]) => ContextId;
Generates a random identifier to track asynchronous execution context.
Parameter request
request object
class DiscoveryModule
class DiscoveryModule {}
class DiscoveryService
class DiscoveryService {}
constructor
constructor(modulesContainer: ModulesContainer);
method createDecorator
static createDecorator: <T>() => DiscoverableDecorator<T>;
Creates a decorator that can be used to decorate classes and methods with metadata. The decorator will also add the class to the collection of discoverable classes (by metadata key). Decorated classes can be discovered using the
getProviders
andgetControllers
methods.Returns
A decorator function.
method getControllers
getControllers: ( options?: DiscoveryOptions, modules?: Module[]) => InstanceWrapper[];
Returns an array of instance wrappers (controllers). Depending on the options, the array will contain either all controllers or only controllers with the specified metadata key.
Parameter options
Discovery options.
Parameter modules
A list of modules to filter by.
Returns
An array of instance wrappers (controllers).
method getMetadataByDecorator
getMetadataByDecorator: <T extends DiscoverableDecorator<any>>( decorator: T, instanceWrapper: InstanceWrapper, methodKey?: string) => T extends DiscoverableDecorator<infer R> ? R : T;
Retrieves metadata from the specified instance wrapper.
Parameter decorator
The decorator to retrieve metadata of.
Parameter instanceWrapper
Reference to the instance wrapper.
Parameter methodKey
An optional method key to retrieve metadata from.
Returns
Discovered metadata.
method getModules
protected getModules: (options?: DiscoveryOptions) => Module[];
Returns a list of modules to be used for discovery.
method getProviders
getProviders: ( options?: DiscoveryOptions, modules?: Module[]) => InstanceWrapper[];
Returns an array of instance wrappers (providers). Depending on the options, the array will contain either all providers or only providers with the specified metadata key.
Parameter options
Discovery options.
Parameter modules
A list of modules to filter by.
Returns
An array of instance wrappers (providers).
class ExternalContextCreator
class ExternalContextCreator {}
constructor
constructor( guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, modulesContainer: ModulesContainer, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, filtersContextCreator: ExternalExceptionFilterContext);
method create
create: < TParamsMetadata extends ParamsMetadata = ParamsMetadata, TContext extends string = ContextType>( instance: Controller, callback: (...args: unknown[]) => unknown, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextId?: ContextId, inquirerId?: string, options?: ExternalContextOptions, contextType?: TContext) => (...args: any[]) => Promise<any>;
method createGuardsFn
createGuardsFn: <TContext extends string = ContextType>( guards: any[], instance: Controller, callback: (...args: any[]) => any, contextType?: TContext) => Function | null;
method createPipesFn
createPipesFn: ( pipes: PipeTransform[], paramsOptions: (ParamProperties & { metatype?: unknown })[]) => (args: unknown[], ...params: unknown[]) => Promise<void>;
method exchangeKeysForValues
exchangeKeysForValues: <TMetadata = any>( keys: string[], metadata: TMetadata, moduleContext: string, paramsFactory: ParamsFactory, contextId?: ContextId, inquirerId?: string, contextFactory?: ( args: unknown[] ) => import('./execution-context-host').ExecutionContextHost) => ParamProperties[];
method fromContainer
static fromContainer: (container: NestContainer) => ExternalContextCreator;
method getContextModuleKey
getContextModuleKey: (moduleCtor: Function | undefined) => string;
method getMetadata
getMetadata: <TMetadata, TContext extends string = ContextType>( instance: Controller, methodName: string, metadataKey?: string, paramsFactory?: ParamsFactory, contextType?: TContext) => ExternalHandlerMetadata;
method getParamValue
getParamValue: <T>( value: T, { metatype, type, data }: { metatype: any; type: any; data: any }, pipes: PipeTransform[]) => Promise<any>;
method registerRequestProvider
registerRequestProvider: <T = any>(request: T, contextId: ContextId) => void;
method transformToResult
transformToResult: (resultOrDeferred: any) => Promise<any>;
class GraphInspector
class GraphInspector {}
constructor
constructor(container: NestContainer);
method insertAttachedEnhancer
insertAttachedEnhancer: (wrapper: InstanceWrapper) => void;
method insertClassNode
insertClassNode: ( moduleRef: Module, wrapper: InstanceWrapper, type: Exclude<Node['metadata']['type'], 'module'>) => void;
method insertEnhancerMetadataCache
insertEnhancerMetadataCache: (entry: EnhancerMetadataCacheEntry) => void;
method insertEntrypointDefinition
insertEntrypointDefinition: <T>( definition: Entrypoint<T>, parentId: string) => void;
method insertOrphanedEnhancer
insertOrphanedEnhancer: (entry: OrphanedEnhancerDefinition) => void;
method inspectInstanceWrapper
inspectInstanceWrapper: <T = any>( source: InstanceWrapper<T>, moduleRef: Module) => void;
method inspectModules
inspectModules: (modules?: Map<string, Module>) => void;
method registerPartial
registerPartial: (error: unknown) => void;
class HttpAdapterHost
class HttpAdapterHost<T extends AbstractHttpAdapter = AbstractHttpAdapter> {}
Defines the
HttpAdapterHost
object.HttpAdapterHost
wraps the underlying platform-specificHttpAdapter
. TheHttpAdapter
is a wrapper around the underlying native HTTP server library (e.g., Express). TheHttpAdapterHost
object provides methods toget
andset
the underlying HttpAdapter.See Also
[Http adapter](https://docs.nestjs.com/faq/http-adapter)
property httpAdapter
httpAdapter: AbstractHttpAdapter<any, any, any>;
Accessor for the underlying
HttpAdapter
Example 1
const httpAdapter = adapterHost.httpAdapter;
class InitializeOnPreviewAllowlist
class InitializeOnPreviewAllowlist {}
class LazyModuleLoader
class LazyModuleLoader {}
constructor
constructor( dependenciesScanner: DependenciesScanner, instanceLoader: InstanceLoader<Injector>, moduleCompiler: ModuleCompiler, modulesContainer: ModulesContainer, moduleOverrides?: ModuleOverride[]);
method load
load: ( loaderFn: () => | Promise<Type<unknown> | DynamicModule> | Type<unknown> | DynamicModule, loadOpts?: LazyModuleLoaderLoadOptions) => Promise<ModuleRef>;
class MetadataScanner
class MetadataScanner {}
method getAllFilteredMethodNames
getAllFilteredMethodNames: (prototype: object) => IterableIterator<string>;
See Also
getAllMethodNames
Deprecated
method getAllMethodNames
getAllMethodNames: (prototype: object | null) => string[];
method scanFromPrototype
scanFromPrototype: <T extends Injectable, R = any>( instance: T, prototype: object, callback: (name: string) => R) => R[];
See Also
getAllMethodNames
Deprecated
class MiddlewareBuilder
class MiddlewareBuilder implements MiddlewareConsumer {}
constructor
constructor( routesMapper: RoutesMapper, httpAdapter: HttpServer, routeInfoPathExtractor: RouteInfoPathExtractor);
method apply
apply: ( ...middleware: Array<Type<any> | Function | any>) => MiddlewareConfigProxy;
method build
build: () => MiddlewareConfiguration[];
method getHttpAdapter
getHttpAdapter: () => HttpServer;
class ModuleRef
abstract class ModuleRef extends AbstractInstanceResolver {}
constructor
constructor(container: NestContainer);
property container
protected readonly container: NestContainer;
property injector
protected readonly injector: Injector;
property instanceLinksHost
readonly instanceLinksHost: InstanceLinksHost;
method create
abstract create: <T = any>(type: Type<T>, contextId?: ContextId) => Promise<T>;
method get
abstract get: { <TInput = any, TResult = TInput>( typeOrToken: Type<TInput> | Function | string | symbol ): TResult; <TInput = any, TResult = TInput>( typeOrToken: any, options: { strict?: boolean; each?: false } ): TResult; <TInput = any, TResult = TInput>( typeOrToken: any, options: { strict?: boolean; each: true } ): TResult[]; <TInput = any, TResult = TInput>( typeOrToken: any, options?: ModuleRefGetOrResolveOpts ): TResult | TResult[];};
Retrieves an instance of either injectable or controller, otherwise, throws exception.
Returns
{TResult}
Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
Returns
{Array}
Retrieves an instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
Returns
{TResult | Array}
method instantiateClass
protected instantiateClass: <T = any>( type: Type<T>, moduleRef: Module, contextId?: ContextId) => Promise<T>;
method introspect
introspect: <T = any>(token: Type<T> | string | symbol) => IntrospectionResult;
method registerRequestByContextId
registerRequestByContextId: <T = any>(request: T, contextId: ContextId) => void;
method resolve
abstract resolve: { <TInput = any, TResult = TInput>( typeOrToken: Type<TInput> | Function | string | symbol ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number } ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number }, options?: { strict?: boolean; each?: false } ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number }, options?: { strict?: boolean; each: true } ): Promise<TResult[]>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number }, options?: ModuleRefGetOrResolveOpts ): Promise<TResult | TResult[]>;};
Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
Returns
{Array}
Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
Returns
{Array}
Resolves transient or request-scoped instance (or a list of instances) of either injectable or controller, otherwise, throws exception.
Returns
{Promise<TResult | Array>}
class ModulesContainer
class ModulesContainer extends Map<string, Module> {}
property applicationId
readonly applicationId: string;
method getById
getById: (id: string) => Module | undefined;
class NestApplication
class NestApplication extends NestApplicationContext<NestApplicationOptions> implements INestApplication {}
constructor
constructor( container: NestContainer, httpAdapter: HttpServer, config: ApplicationConfig, graphInspector: GraphInspector, appOptions?: NestApplicationOptions);
property logger
protected readonly logger: Logger;
method applyOptions
applyOptions: () => void;
method connectMicroservice
connectMicroservice: <T extends object>( microserviceOptions: T, hybridAppOptions?: NestHybridApplicationOptions) => INestMicroservice;
method createServer
createServer: <T = any>() => T;
method dispose
protected dispose: () => Promise<void>;
method enableCors
enableCors: (options?: CorsOptions | CorsOptionsDelegate<any>) => void;
method enableVersioning
enableVersioning: (options?: VersioningOptions) => this;
method getHttpAdapter
getHttpAdapter: () => AbstractHttpAdapter;
method getHttpServer
getHttpServer: () => any;
method getMicroservices
getMicroservices: () => INestMicroservice[];
method getUnderlyingHttpServer
getUnderlyingHttpServer: <T>() => T;
method getUrl
getUrl: () => Promise<string>;
method init
init: () => Promise<this>;
method listen
listen: { (port: number | string): Promise<any>; (port: string | number, hostname: string): Promise<any>;};
method registerHttpServer
registerHttpServer: () => void;
method registerModules
registerModules: () => Promise<void>;
method registerParserMiddleware
registerParserMiddleware: () => void;
method registerRouter
registerRouter: () => Promise<void>;
method registerRouterHooks
registerRouterHooks: () => Promise<void>;
method registerWsModule
registerWsModule: () => void;
method setBaseViewsDir
setBaseViewsDir: (path: string | string[]) => this;
method setGlobalPrefix
setGlobalPrefix: (prefix: string, options?: GlobalPrefixOptions) => this;
method setViewEngine
setViewEngine: (engineOrOptions: any) => this;
method startAllMicroservices
startAllMicroservices: () => Promise<this>;
method use
use: (args_0: any, args_1?: any) => this;
method useBodyParser
useBodyParser: (args_0: any, args_1?: any) => this;
method useGlobalFilters
useGlobalFilters: (...filters: ExceptionFilter[]) => this;
method useGlobalGuards
useGlobalGuards: (...guards: CanActivate[]) => this;
method useGlobalInterceptors
useGlobalInterceptors: (...interceptors: NestInterceptor[]) => this;
method useGlobalPipes
useGlobalPipes: (...pipes: PipeTransform<any>[]) => this;
method useStaticAssets
useStaticAssets: { (options: any): this; (path: string, options?: any): this };
method useWebSocketAdapter
useWebSocketAdapter: (adapter: WebSocketAdapter) => this;
class NestApplicationContext
class NestApplicationContext< TOptions extends NestApplicationContextOptions = NestApplicationContextOptions > extends AbstractInstanceResolver implements INestApplicationContext {}
constructor
constructor( container: NestContainer, appOptions?: NestApplicationContextOptions, contextModule?: Module, scope?: Type<any>[]);
property appOptions
protected readonly appOptions: NestApplicationContextOptions;
property container
protected readonly container: NestContainer;
property injector
protected injector: Injector;
property instanceLinksHost
readonly instanceLinksHost: InstanceLinksHost;
property isInitialized
protected isInitialized: boolean;
property logger
protected readonly logger: Logger;
method assertNotInPreviewMode
protected assertNotInPreviewMode: (methodName: string) => void;
method callBeforeShutdownHook
protected callBeforeShutdownHook: (signal?: string) => Promise<void>;
Calls the
beforeApplicationShutdown
function on the registered modules and children.
method callBootstrapHook
protected callBootstrapHook: () => Promise<void>;
Calls the
onApplicationBootstrap
function on the registered modules and its children.
method callDestroyHook
protected callDestroyHook: () => Promise<void>;
Calls the
onModuleDestroy
function on the registered modules and its children.
method callInitHook
protected callInitHook: () => Promise<void>;
Calls the
onModuleInit
function on the registered modules and its children.
method callShutdownHook
protected callShutdownHook: (signal?: string) => Promise<void>;
Calls the
onApplicationShutdown
function on the registered modules and children.
method close
close: (signal?: string) => Promise<void>;
Terminates the application
Returns
{Promise}
method dispose
protected dispose: () => Promise<void>;
method enableShutdownHooks
enableShutdownHooks: (signals?: (ShutdownSignal | string)[]) => this;
Enables the usage of shutdown hooks. Will call the
onApplicationShutdown
function of a provider if the process receives a shutdown signal.Parameter signals
The system signals it should listen to
Returns
{this} The Nest application context instance
method flushLogs
flushLogs: () => void;
Prints buffered logs and detaches buffer.
Returns
{void}
method flushLogsOnOverride
flushLogsOnOverride: () => void;
Define that it must flush logs right after defining a custom logger.
method get
get: { <TInput = any, TResult = TInput>( typeOrToken: Type<TInput> | Function | string | symbol ): TResult; <TInput = any, TResult = TInput>( typeOrToken: any, options: { strict?: boolean; each?: false } ): TResult; <TInput = any, TResult = TInput>( typeOrToken: any, options: { strict?: boolean; each: true } ): TResult[];};
Retrieves an instance of either injectable or controller, otherwise, throws exception.
Returns
{TResult}
Retrieves a list of instances of either injectables or controllers, otherwise, throws exception.
Returns
{Array}
method init
init: () => Promise<this>;
Initializes the Nest application. Calls the Nest lifecycle events.
Returns
{Promise} The NestApplicationContext instance as Promise
method listenToShutdownSignals
protected listenToShutdownSignals: (signals: string[]) => void;
Listens to shutdown signals by listening to process events
Parameter signals
The system signals it should listen to
method registerRequestByContextId
registerRequestByContextId: <T = any>(request: T, contextId: ContextId) => void;
Registers the request/context object for a given context ID (DI container sub-tree).
Returns
{void}
method resolve
resolve: { <TInput = any, TResult = TInput>( typeOrToken: Type<TInput> | Function | string | symbol ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number } ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number }, options?: { strict?: boolean; each?: false } ): Promise<TResult>; <TInput = any, TResult = TInput>( typeOrToken: any, contextId?: { id: number }, options?: { strict?: boolean; each: true } ): Promise<TResult[]>;};
Resolves transient or request-scoped instance of either injectable or controller, otherwise, throws exception.
Returns
{Array}
Resolves transient or request-scoped instances of either injectables or controllers, otherwise, throws exception.
Returns
{Array}
method select
select: <T>(moduleType: Type<T> | DynamicModule) => INestApplicationContext;
Allows navigating through the modules tree, for example, to pull out a specific instance from the selected module.
Returns
{INestApplicationContext}
method selectContextModule
selectContextModule: () => void;
method unsubscribeFromProcessSignals
protected unsubscribeFromProcessSignals: () => void;
Unsubscribes from shutdown signals (process events)
method useLogger
useLogger: (logger: LoggerService | LogLevel[] | false) => void;
Sets custom logger service. Flushes buffered logs if auto flush is on.
Returns
{void}
class NestContainer
class NestContainer {}
constructor
constructor(_applicationConfig?: ApplicationConfig);
property applicationConfig
readonly applicationConfig: ApplicationConfig;
property serializedGraph
readonly serializedGraph: SerializedGraph;
method addController
addController: (controller: Type<any>, token: string) => void;
method addDynamicMetadata
addDynamicMetadata: ( token: string, dynamicModuleMetadata: DynamicModule, scope: Type<any>[]) => Promise<void>;
method addDynamicModules
addDynamicModules: (modules: any[], scope: Type<any>[]) => Promise<void>;
method addExportedProvider
addExportedProvider: (provider: Type<any>, token: string) => void;
method addGlobalModule
addGlobalModule: (module: Module) => void;
method addImport
addImport: ( relatedModule: Type<any> | DynamicModule, token: string) => Promise<void>;
method addInjectable
addInjectable: ( injectable: Provider, token: string, enhancerSubtype: EnhancerSubtype, host?: Type<Injectable>) => | string | symbol | Function | import('./instance-wrapper').InstanceWrapper<unknown>;
method addModule
addModule: ( metatype: ModuleMetatype, scope: ModuleScope) => Promise<{ moduleRef: Module; inserted: boolean } | undefined>;
method addProvider
addProvider: ( provider: Provider, token: string, enhancerSubtype?: EnhancerSubtype) => string | symbol | Function;
method bindGlobalModuleToModule
bindGlobalModuleToModule: (target: Module, globalModule: Module) => void;
method bindGlobalScope
bindGlobalScope: () => void;
method bindGlobalsToImports
bindGlobalsToImports: (moduleRef: Module) => void;
method clear
clear: () => void;
method getDynamicMetadataByToken
getDynamicMetadataByToken: { (token: string): DynamicModule; <K extends string | number | symbol>( token: string, metadataKey: K ): DynamicModule;};
method getHttpAdapterHostRef
getHttpAdapterHostRef: () => import('..').HttpAdapterHost< import('..').AbstractHttpAdapter<any, any, any>>;
method getHttpAdapterRef
getHttpAdapterRef: () => import('..').AbstractHttpAdapter<any, any, any>;
method getInternalCoreModuleRef
getInternalCoreModuleRef: () => Module | undefined;
method getModuleByKey
getModuleByKey: (moduleKey: string) => Module;
method getModuleCompiler
getModuleCompiler: () => ModuleCompiler;
method getModules
getModules: () => ModulesContainer;
method getModuleTokenFactory
getModuleTokenFactory: () => ModuleTokenFactory;
method isGlobalModule
isGlobalModule: ( metatype: Type<any>, dynamicMetadata?: DynamicModule) => boolean;
method registerCoreModuleRef
registerCoreModuleRef: (moduleRef: Module) => void;
method registerRequestProvider
registerRequestProvider: <T = any>(request: T, contextId: ContextId) => void;
method replace
replace: (toReplace: any, options: any & { scope: any[] | null }) => void;
method replaceModule
replaceModule: ( metatypeToReplace: ModuleMetatype, newMetatype: ModuleMetatype, scope: ModuleScope) => Promise<{ moduleRef: Module; inserted: boolean } | undefined>;
method setHttpAdapter
setHttpAdapter: (httpAdapter: any) => void;
class PartialGraphHost
class PartialGraphHost {}
class Reflector
class Reflector {}
Helper class providing Nest reflection capabilities.
See Also
[Reflection](https://docs.nestjs.com/guards#putting-it-all-together)
method createDecorator
static createDecorator: { <TParam>( options?: CreateDecoratorOptions<TParam> ): ReflectableDecorator<TParam>; <TParam, TTransformed>( options: CreateDecoratorWithTransformOptions<TParam, TTransformed> ): ReflectableDecorator<TParam, TTransformed>;};
Creates a decorator that can be used to decorate classes and methods with metadata. Can be used as a strongly-typed alternative to
@SetMetadata
.Parameter options
Decorator options.
Returns
A decorator function.
method get
get: { <T extends ReflectableDecorator<any, any>>( decorator: T, target: Type<any> | Function ): T extends ReflectableDecorator<any, infer R> ? R : unknown; <TResult = any, TKey = any>(metadataKey: TKey, target: any): TResult;};
Retrieve metadata for a reflectable decorator for a specified target.
Parameter decorator
reflectable decorator created through
Reflector.createDecorator
Parameter target
context (decorated object) to retrieve metadata from
Example 1
const roles = this.reflector.get(Roles, context.getHandler());
Retrieve metadata for a specified key for a specified target.
Parameter metadataKey
lookup key for metadata to retrieve
Parameter target
context (decorated object) to retrieve metadata from
Example 1
const roles = this.reflector.get<string[]>('roles', context.getHandler());
method getAll
getAll: { <T extends ReflectableDecorator<any, any>>( decorator: T, targets: (Type<any> | Function)[] ): T extends ReflectableDecorator<infer R, infer R> ? R extends any[] ? R : R[] : unknown; <TResult extends any[] = any[], TKey = any>( metadataKey: TKey, targets: any[] ): TResult;};
Retrieve metadata for a specified decorator for a specified set of targets.
Parameter decorator
lookup decorator for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
Retrieve metadata for a specified key for a specified set of targets.
Parameter metadataKey
lookup key for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
method getAllAndMerge
getAllAndMerge: { <T extends ReflectableDecorator<any, any>>( decorator: T, targets: (Type<any> | Function)[] ): T extends ReflectableDecorator<infer R, infer R> ? R : unknown; <TResult extends object | any[] = any[], TKey = any>( metadataKey: TKey, targets: any[] ): TResult;};
Retrieve metadata for a specified decorator for a specified set of targets and merge results.
Parameter decorator
lookup decorator for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
Retrieve metadata for a specified key for a specified set of targets and merge results.
Parameter metadataKey
lookup key for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
method getAllAndOverride
getAllAndOverride: { <T extends ReflectableDecorator<any, any>>( decorator: T, targets: (Type<any> | Function)[] ): T extends ReflectableDecorator<infer R, infer R> ? R : unknown; <TResult = any, TKey = any>(metadataKey: TKey, targets: any[]): TResult;};
Retrieve metadata for a specified decorator for a specified set of targets and return a first not undefined value.
Parameter decorator
lookup decorator for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
Retrieve metadata for a specified key for a specified set of targets and return a first not undefined value.
Parameter metadataKey
lookup key for metadata to retrieve
Parameter targets
context (decorated objects) to retrieve metadata from
class RouterModule
class RouterModule {}
constructor
constructor(modulesContainer: ModulesContainer, routes: Routes);
method register
static register: (routes: Routes) => DynamicModule;
class SerializedGraph
class SerializedGraph {}
method getNodeById
getNodeById: (id: string) => Node;
method insertAttachedEnhancer
insertAttachedEnhancer: (nodeId: string) => void;
method insertEdge
insertEdge: (edgeDefinition: WithOptionalId<Edge>) => { id: string; metadata: | ({ type: 'module-to-module' } & { sourceModuleName: string; targetModuleName: string; }) | ({ type: 'class-to-class'; sourceClassName: string; targetClassName: string; sourceClassToken: InjectionToken; targetClassToken: InjectionToken; injectionType: 'constructor' | 'property' | 'decorator'; keyOrIndex?: string | number | symbol; internal?: boolean; } & { sourceModuleName: string; targetModuleName: string }); source: string; target: string;};
method insertEntrypoint
insertEntrypoint: <T>(definition: Entrypoint<T>, parentId: string) => void;
method insertNode
insertNode: (nodeDefinition: Node) => Node;
method insertOrphanedEnhancer
insertOrphanedEnhancer: (entry: OrphanedEnhancerDefinition) => void;
method toJSON
toJSON: () => SerializedGraphJson;
method toString
toString: () => string;
Interfaces
interface ContextId
interface ContextId {}
interface ContextIdResolver
interface ContextIdResolver {}
interface ContextIdStrategy
interface ContextIdStrategy<T = any> {}
method attach
attach: ( contextId: ContextId, request: T) => ContextIdResolverFn | ContextIdResolver | undefined;
Allows to attach a parent context id to the existing child context id. This lets you construct durable DI sub-trees that can be shared between contexts.
Parameter contextId
auto-generated child context id
Parameter request
request object
interface CreateDecoratorOptions
interface CreateDecoratorOptions<TParam = any, TTransformed = TParam> {}
interface ExternalContextOptions
interface ExternalContextOptions {}
property filters
filters?: boolean;
property guards
guards?: boolean;
property interceptors
interceptors?: boolean;
interface FilterByInclude
interface FilterByInclude {}
property include
include?: Function[];
List of modules to include (whitelist) into the discovery process.
interface FilterByMetadataKey
interface FilterByMetadataKey {}
property metadataKey
metadataKey?: string;
A key to filter controllers and providers by. Only instance wrappers with the specified metadata key will be returned.
interface HostComponentInfo
interface HostComponentInfo {}
property isTreeDurable
isTreeDurable: boolean;
Flag that indicates whether DI subtree is durable
property token
token: InjectionToken;
Injection token (or class reference)
interface ModuleRefGetOrResolveOpts
interface ModuleRefGetOrResolveOpts {}
interface ParamsFactory
interface ParamsFactory {}
method exchangeKeyForValue
exchangeKeyForValue: (type: number, data: ParamData, args: any) => any;
Type Aliases
type ContextIdResolverFn
type ContextIdResolverFn = (info: HostComponentInfo) => ContextId;
type DiscoverableDecorator
type DiscoverableDecorator<T> = ((opts?: T) => CustomDecorator) & { KEY: string;};
type DiscoveryOptions
type DiscoveryOptions = FilterByInclude | FilterByMetadataKey;
type ReflectableDecorator
type ReflectableDecorator<TParam, TTransformed = TParam> = (( opts?: TParam) => CustomDecorator) & { KEY: string;};
type Routes
type Routes = RouteTree[];
type SerializedGraphStatus
type SerializedGraphStatus = 'partial' | 'complete';
Package Files (30)
- adapters/http-adapter.d.ts
- application-config.d.ts
- constants.d.ts
- discovery/discovery-module.d.ts
- discovery/discovery-service.d.ts
- exceptions/base-exception-filter.d.ts
- helpers/context-id-factory.d.ts
- helpers/external-context-creator.d.ts
- helpers/http-adapter-host.d.ts
- index.d.ts
- injector/container.d.ts
- injector/inquirer/inquirer-constants.d.ts
- injector/instance-wrapper.d.ts
- injector/lazy-module-loader/lazy-module-loader.d.ts
- injector/module-ref.d.ts
- injector/modules-container.d.ts
- inspector/graph-inspector.d.ts
- inspector/initialize-on-preview.allowlist.d.ts
- inspector/partial-graph.host.d.ts
- inspector/serialized-graph.d.ts
- metadata-scanner.d.ts
- middleware/builder.d.ts
- nest-application-context.d.ts
- nest-application.d.ts
- nest-factory.d.ts
- repl/repl.d.ts
- router/interfaces/routes.interface.d.ts
- router/request/request-constants.d.ts
- router/router-module.d.ts
- services/reflector.service.d.ts
Dependencies (6)
Dev Dependencies (1)
Peer Dependencies (6)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@nestjs/core
.
- Markdown[](https://www.jsdocs.io/package/@nestjs/core)
- HTML<a href="https://www.jsdocs.io/package/@nestjs/core"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 6995 ms. - Missing or incorrect documentation? Open an issue for this package.