{"id":353,"date":"2022-07-30T00:00:00","date_gmt":"2022-07-30T00:00:00","guid":{"rendered":"https:\/\/tac.debuzzify.com\/?p=353"},"modified":"2023-06-20T02:51:28","modified_gmt":"2023-06-20T02:51:28","slug":"toml-config-files","status":"publish","type":"post","link":"https:\/\/www.the-analytics.club\/toml-config-files\/","title":{"rendered":"A Brief Guide To Manage Configurations Using TOML Files"},"content":{"rendered":"\n
How’d you change the behavior of a software project based on a set of parameters?<\/p>\n\n\n\n
You could use environment variables. But what if you want complex structures in the parameters?<\/p>\n\n\n\n
Can you use JSON? Yes, you can. JSON files don’t allow comments. How’d you describe your parameters to readers?<\/p>\n\n\n\n
The answer is to use a TOML configuration file.<\/p>\n\n\n\n\n\n
Config files are great ways to extract project parameters. When you share your code with others, they know exactly where to make changes to tweak the behavior of the software.<\/p>\n\n\n\n
For instance, say yours is a website codebase that supports several themes. Others who set up your code can go to the config file and change the theme variable to a different one. It’s more convenient than going to the codebase and editing the theme in various files.<\/p>\n\n\n\n
But to let your users know what themes are available, you need to have comments on the config files. Your website supports ‘dark,’ ‘light,’ ‘pop,’ and ‘grayscale’ themes. JSON files fall short, as they don’t allow comments.<\/p>\n\n\n\n
It’s a misconception that environment files are config files<\/b>. They are not.<\/p>\n\n\n\n
While it’s also possible to store values in the environment file<\/a>, its purpose is to hide secrets from other developers.<\/p>\n\n\n\n Say you have database credentials and API keys. Publishing your code with these values to a public cloud like GitHub can be harmful. Hence we use env variables to separate them.<\/p>\n\n\n\n Related: <\/b>11 Advantages of Cloud Databases Over On-Premise Databases.<\/i><\/b><\/a><\/p>\n\n\n\n Config files are to store values that you can happily share with other developers. The themes option we discussed is a good example.<\/p>\n\n\n\n Why TOML?<\/p>\n\n\n\n TOML is an excellent option because it’s both super straightforward and the most popular platforms accept it.\u00a0<\/p>\n\n\n\n For instance, the popular headless CMS platform Netlify uses TOML files<\/a> to upload build configurations. We can configure the node environment, the build command, the output directory, etc., in this config file. <\/p>\n\n\n\n