admin管理员组

文章数量:1435859

I’m a bit confused about the different configuration file formats: dotenv, YAML, INI, CFG(inc: .conf, .cfg, .config), and TOML. They all seem to serve the same purpose of storing configurations, keys and secrets but I’m not sure which one to use in different types of projects.

Could someone explain in what type of project and how I should decide which one to use for each case?

I know that YAML can also serve the purpose of transmitting structured data, like JSON and XML, but I'm referring to it in the context of being used for configuration/secret storage.

I’m a bit confused about the different configuration file formats: dotenv, YAML, INI, CFG(inc: .conf, .cfg, .config), and TOML. They all seem to serve the same purpose of storing configurations, keys and secrets but I’m not sure which one to use in different types of projects.

Could someone explain in what type of project and how I should decide which one to use for each case?

I know that YAML can also serve the purpose of transmitting structured data, like JSON and XML, but I'm referring to it in the context of being used for configuration/secret storage.

Share Improve this question asked Jan 30 at 18:56 LegsNotHandLegsNotHand 234 bronze badges 1
  • 2 you fot plain old json files, text files, environment variables, secrets, key vaults, storage buckets, and command line options. There's no right or wrong - just keep calm and configure on. – topsail Commented Jan 30 at 19:01
Add a comment  | 

1 Answer 1

Reset to default 1

Short answer, it depends on the tech. Node projects, for instance, have to be configured by JSON, but from there are different config flavors depending on your project architecture. Next.js servers will require additional configurations with their own set of rules. Typescript requires an additional configuration. So do the testing libraries and linters. Using Babel? Gonna need more config!

On top of this, there are different package managers that can be run on top of Node including NPM, Yarn, and PNPM, each with its own configuration preference. To confuse things more, there are certain architectures and libraries that will accept different types of configuration files, and might support, say, both YAML and JSON config files.

How to keep from being confused? Well, if your config files are missing your application won't work. It will at least throw an error and at worst refuse to run. The "decision" to be made will mostly be based on what the application supports and what you're most comfortable with. If I have a choice between YAML and JSON, I can appreciate that YAML might provide additional flexibility, but I'm more comfortable with JSON so I'll choose it every time. If I hit a roadblock where there's something I just CAN'T do using JSON...well I guess it's time to learn some YAML!

tl;dr: It depends! Basically it's project dependent.

本文标签: configWhen to Use dotenvyamliniCFG and TOML in ProjectStack Overflow