0.1.9 • Published 10 months ago
@gallofeliz/config v0.1.9
Config
Note: This module is part of @gallofeliz/js-libs that is a personal project. It is not developed nor tested for applications that need high security or scalability.
Advanced config:
- from files (super-yaml, json) and envs (scoped or not)
- Validated user config (with validate component with cast and defaults values)
- Finalization fn to transform user config to config
- watch changes and emit on change new config
- watch alerts in case of no listen on watch events
- watch changes included files
- include files into config from envs (ex: APP_DB_PASSWORD='!include /run/secrets/db_password')
- Super Json (like Yaml, for example { db: { password: { $include: '/run/secrets/db_password' }, username: { $env: 'USER' } } })
- Command line arguments as config param
Example:
import {loadConfig} from '@gallofeliz/config'
const watchEventEmitter = new EventEmitter
watchEventEmitter.on('change:machin.truc', ({value/*, previousValue, config, previousConfig*/}) => {
// Update service
machinService.setTruc(value)
})
deepEqual(
await loadConfig<Config, Config>({
defaultFilename: __dirname + '/config.test.yml',
logger: createLogger(),
envFilename: 'config',
envPrefix: 'app',
userProvidedConfigSchema: tsToJsSchema<Config>(),
watchChanges: {
onChange({config/*, previousConfig, patch*/}) {
console.log('My new config', config)
}
eventEmitter: watchEventEmitter
}
}),
{
machin: {
truc: {
bidule: true
}
},
envShell: 'hello world'
}
)
const machinService = new MachinService(config.machin)