json-configuration-parser
Utility to load JSON configuration file like .env files with a TS file to type values. (no depth)
Examples
Given the following JSON file
{
"hello": "world"
}
We can load the configuration file in process.env with the identifiers as the key to find them, and a TS file will be created dynamically to type the configuration.
const { configJsonSync } = require('json-configuration-parser');
configJsonSync();
console.log(process.env.hello); // "world"
or
We can take back the object (configuration) and use it as we want (a TS file will not be emitted then)
const { configJsonSync } = require('json-configuration-parser');
const configuration = configJsonSync(true);
You can also find your configuration elsewhere than the root of the project directory (relative to package.json) givin a path
const { configJsonSync } = require('json-configuration-parser');
configJsonSync('path-to-my-json-file');
console.log(process.env.hello); // "world"
And there is two version of the function to load JSON files, sync or async
const { configJson } = require('json-configuration-parser');
(async () => {
await configJson();
console.log(process.env.hello); // "world"
})();