4 ms·
I've recently settled on typescript object literals for creating complex config files. Adv: - It's still quite declarative. - supports expressions. - suppor
by shusson 8y ago
I've recently settled on typescript object literals for creating complex config files.
Adv:
- It's still quite declarative.
- supports expressions.
- supports merging objects using the spread `...` operator. This enables breaking up large configs files into smaller files.
- supports type constraints.
- serialises to JSON easily.
- tobyhinloopen 8y agoSame here... just using the same language as the rest application, usually a file with constants or a class/struct/module/whatever. the only reason config files in another language might be required is when you require configuring the application after it is compiled to native binary code. Obviously this doesn't apply to all these applications written in scripting languages. I do wonder how you create type-safe config files though. I currently have a `development.ts` and a `production.ts`, where the `production.ts` is only loaded when `node_env === production`. `production.ts` contains blank/default values and the file is overwritten on the server with production secrets.
- shusson 8y ago> I do wonder how you create type-safe config files though The types help prevent erroneous config declarations. e.g ``` enum LogLevel { Info = "info", Debug = "debug" } const MyConfig = { logOptions: { level: LogLevel.Debug } }; ``` And since we serialise `MyConfig`, the config has to be transpiled by Typescript.