## Why? Configuration management is hard. * Multiple environments mean multiple `.env` files * `.env` files are a list of keys and values, they have no structure * No runtime validation (you can check for existence of environment variables, but not
npm install @barath/typed-configtyped-config.env files.env files are a list of keys and values, they have no structure## How?
* Create a ./config directory in your project root
* Add a default.yml in this folder and populate it with your configuration
``yamlbunyan
# example for logger config`
logger:
name: my-awesome-project
level: info
class-validator to define validations
* Create a class that represents your configuration using the amazing
``typescript`
import { IsDefined } from 'class-validator'
import { LoggerOptions } from 'bunyan'
export class Config {
@IsDefined()
logger: LoggerOptions
}
index.ts
* In the (or whatever your main file is) load the config`
typescript
import { loadConfig } from '@barath/typed-config'
import { Config } from './lib/config'
import bunyan from 'bunyan'
export const config = loadConfig(Config)
export const logger = bunyan.createLogger(config.logger)
logger.info('hello world')
``