@nestjs/config
- Version 3.2.3
- Published
- 49.5 kB
- 3 dependencies
- MIT license
Install
npm i @nestjs/config
yarn add @nestjs/config
pnpm add @nestjs/config
Overview
Nest - modern, fast, powerful node.js web framework (@config)
Index
Functions
Classes
Interfaces
Type Aliases
Functions
function getConfigToken
getConfigToken: (token: string) => string;
function registerAs
registerAs: < TConfig extends ConfigObject, TFactory extends ConfigFactory<ConfigObject> = ConfigFactory<TConfig>>( token: string, configFactory: TFactory) => TFactory & ConfigFactoryKeyHost<ReturnType<TFactory>>;
Registers the configuration object behind a specified token.
Classes
class ConditionalModule
class ConditionalModule {}
method registerWhen
static registerWhen: ( module: ModuleMetadata, condition: string | ((env: NodeJS.ProcessEnv) => boolean), options?: { timeout?: number; debug?: boolean }) => Promise<Required<Pick<DynamicModule, 'imports' | 'exports' | 'module'>>>;
class ConfigModule
class ConfigModule {}
property envVariablesLoaded
static readonly envVariablesLoaded: Promise<void>;
This promise resolves when "dotenv" completes loading environment variables. When "ignoreEnvFile" is set to true, then it will resolve immediately after the "ConfigModule#forRoot" method is called.
method forFeature
static forFeature: (config: ConfigFactory) => DynamicModule;
Registers configuration object (partial registration).
Parameter config
method forRoot
static forRoot: (options?: ConfigModuleOptions) => DynamicModule;
Loads process environment variables depending on the "ignoreEnvFile" flag and "envFilePath" value. Also, registers custom configurations globally.
Parameter options
class ConfigService
class ConfigService< K = Record<string, unknown>, WasValidated extends boolean = false> {}
constructor
constructor(internalConfig?: Record<string, any>);
property changes$
readonly changes$: any;
Returns a stream of configuration changes. Each event contains the attribute path, the old value and the new value.
method get
get: { <T = any>(propertyPath: KeyOf<K>): ValidatedResult<WasValidated, T>; <T = K, P extends Path<T> = any, R = PathValue<T, P>>( propertyPath: P, options: ConfigGetOptions ): ValidatedResult<WasValidated, R>; <T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): T; <T = K, P extends Path<T> = any, R = PathValue<T, P>>( propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions ): Exclude<R, undefined>;};
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
Parameter propertyPath
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
Parameter propertyPath
Parameter options
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist.
Parameter propertyPath
Parameter defaultValue
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist.
Parameter propertyPath
Parameter defaultValue
Parameter options
method getOrThrow
getOrThrow: { <T = any>(propertyPath: KeyOf<K>): Exclude<T, undefined>; <T = K, P extends Path<T> = any, R = PathValue<T, P>>( propertyPath: P, options: ConfigGetOptions ): Exclude<R, undefined>; <T = any>(propertyPath: KeyOf<K>, defaultValue: NoInferType<T>): Exclude< T, undefined >; <T = K, P extends Path<T> = any, R = PathValue<T, P>>( propertyPath: P, defaultValue: NoInferType<R>, options: ConfigGetOptions ): Exclude<R, undefined>;};
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
Parameter propertyPath
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host").
Parameter propertyPath
Parameter options
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist. If the default value is undefined an exception will be thrown.
Parameter propertyPath
Parameter defaultValue
Get a configuration value (either custom configuration or process environment variable) based on property path (you can use dot notation to traverse nested object, e.g. "database.host"). It returns a default value if the key does not exist. If the default value is undefined an exception will be thrown.
Parameter propertyPath
Parameter defaultValue
Parameter options
method set
set: <T = any>(propertyPath: KeyOf<K>, value: T) => void;
Sets a configuration value based on property path.
Parameter propertyPath
Parameter value
method setEnvFilePaths
setEnvFilePaths: (paths: string[]) => void;
Sets env file paths from
config.module.ts
to parse.Parameter paths
Interfaces
interface ConfigChangeEvent
interface ConfigChangeEvent<OldValue = any, NewValue = any> {}
Represents a change in the configuration object. Dispatched when one updates the configuration object through the
ConfigService#set
method.
interface ConfigFactoryKeyHost
interface ConfigFactoryKeyHost<T = unknown> {}
property KEY
KEY: string;
method asProvider
asProvider: () => { imports: [ReturnType<typeof ConfigModule.forFeature>]; useFactory: (config: T) => T; inject: [string];};
interface ConfigGetOptions
interface ConfigGetOptions {}
property infer
infer: true;
If present, "get" method will try to automatically infer a type of property based on the type argument specified at the "ConfigService" class-level (example: ConfigService).
interface ConfigModuleOptions
interface ConfigModuleOptions {}
property cache
cache?: boolean;
If "true", values from the process.env object will be cached in the memory. This improves the overall application performance. See: https://github.com/nodejs/node/issues/3104
property envFilePath
envFilePath?: string | string[];
Path to the environment file(s) to be loaded.
property expandVariables
expandVariables?: boolean | DotenvExpandOptions;
A boolean value indicating the use of expanded variables, or object containing options to pass to dotenv-expand. If .env contains expanded variables, they'll only be parsed if this property is set to true.
property ignoreEnvFile
ignoreEnvFile?: boolean;
If "true", environment files (
.env
) will be ignored.
property ignoreEnvVars
ignoreEnvVars?: boolean;
If "true", predefined environment variables will not be validated.
property isGlobal
isGlobal?: boolean;
If "true", registers
ConfigModule
as a global module. See: https://docs.nestjs.com/modules#global-modules
property load
load?: Array<ConfigFactory>;
Array of custom configuration files to be loaded. See: https://docs.nestjs.com/techniques/configuration
property validate
validate?: (config: Record<string, any>) => Record<string, any>;
Custom function to validate environment variables. It takes an object containing environment variables as input and outputs validated environment variables. If exception is thrown in the function it would prevent the application from bootstrapping. Also, environment variables can be edited through this function, changes will be reflected in the process.env object.
property validationOptions
validationOptions?: Record<string, any>;
Schema validation options. See: https://joi.dev/api/?v=17.3.0#anyvalidatevalue-options
property validationSchema
validationSchema?: any;
Environment variables validation schema (Joi).
Type Aliases
type ConfigFactory
type ConfigFactory<T extends ConfigObject = ConfigObject> = () => ConfigFactoryReturnValue<T>;
type ConfigObject
type ConfigObject = Record<string, any>;
type ConfigType
type ConfigType<T extends (...args: any) => any> = T extends ( ...args: any) => infer ReturnVal ? ReturnVal extends Promise<infer AsyncReturnVal> ? AsyncReturnVal : ReturnVal : any;
type NoInferType
type NoInferType<T> = [T][T extends any ? 0 : never];
type Path
type Path<T> = keyof T extends string ? PathImpl2<T> extends infer P ? P extends string | keyof T ? P : keyof T : keyof T : never;
type PathImpl
type PathImpl<T, Key extends keyof T> = Key extends string ? IsAny<T[Key]> extends true ? never : T[Key] extends Record<string, any> ? | `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}` | `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}` : never : never;
type PathImpl2
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
type PathValue
type PathValue<T, P extends Path<T>> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? Rest extends Path<T[Key]> ? PathValue<T[Key], Rest> : never : never : P extends keyof T ? T[P] : never;
Package Files (13)
- dist/conditional.module.d.ts
- dist/config.module.d.ts
- dist/config.service.d.ts
- dist/interfaces/config-change-event.interface.d.ts
- dist/interfaces/config-factory.interface.d.ts
- dist/interfaces/config-module-options.interface.d.ts
- dist/types/config-object.type.d.ts
- dist/types/config.type.d.ts
- dist/types/no-infer.type.d.ts
- dist/types/path-value.type.d.ts
- dist/utils/get-config-token.util.d.ts
- dist/utils/register-as.util.d.ts
- index.d.ts
Dependencies (3)
Dev Dependencies (25)
- @commitlint/cli
- @commitlint/config-angular
- @nestjs/common
- @nestjs/core
- @nestjs/platform-express
- @nestjs/testing
- @types/jest
- @types/lodash
- @types/node
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- eslint
- eslint-config-prettier
- eslint-plugin-import
- husky
- jest
- joi
- lint-staged
- prettier
- reflect-metadata
- release-it
- rimraf
- rxjs
- ts-jest
- typescript
Peer Dependencies (2)
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/config
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@nestjs/config)
- HTML<a href="https://www.jsdocs.io/package/@nestjs/config"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4140 ms. - Missing or incorrect documentation? Open an issue for this package.