@sprout-idws/sprout-config-loader
v1.0.1
Published
Reusable NestJS config loader: loads config and secret files from directories into process.env
Downloads
273
Maintainers
Readme
@sprout-idws/sprout-config-loader
NestJS module that loads configuration and secret files from directories into process.env before (and alongside) ConfigModule, matching how Sprout deploys apps with Docker configs and secrets mounted as files.
Purpose
- In Swarm / Sprout deployments, values often arrive as files under
/run/configsand/run/secrets, not only as a single.envfile. - This package reads those directories once at startup and exposes the same values through Nest
ConfigServiceby merging them into the config layer loaded byConfigModule.forRoot.
Installation
npm install @sprout-idws/sprout-config-loader @nestjs/configPeer dependencies: @nestjs/common, @nestjs/config (v10+ / v3+ respectively).
Environment variables
| Variable | Default | Meaning |
|----------|---------|---------|
| CONFIGS_BASE_PATH | /run/configs | Directory of non-secret files (one file per key) |
| SECRETS_BASE_PATH | /run/secrets | Directory of secret files (one file per key) |
Each file name is normalized to an env key: non-alphanumeric characters become _, then the key is uppercased (for example DATABASE_HOST from a file named DATABASE_HOST).
If a key already exists in process.env, the file value is not applied (env wins).
Usage
Register early in your root module (typically global):
import { Module } from '@nestjs/common';
import { ConfigLoaderModule } from '@sprout-idws/sprout-config-loader';
@Module({
imports: [
ConfigLoaderModule.forRoot({
envFilePath: '.env', // optional; passed to ConfigModule.forRoot
isGlobal: true, // default true
}),
],
})
export class AppModule {}ConfigLoaderModule.forRoot:
- Imports
ConfigModule.forRootwithload: [() => ConfigLoaderService.loadConfigFiles()]. - Exports
ConfigModulesoConfigServicesees file-backed values where not overridden.
Local development
Point CONFIGS_BASE_PATH / SECRETS_BASE_PATH at local folders with plain files named like production keys (same layout as in containers).
Exports
ConfigLoaderModule,ConfigLoaderModuleOptionsConfigLoaderService(staticloadConfigFiles()used by the module loader)
Repository
sprout-typescript-backend — packages/sprout-config-loader.
