json-configuration-parser
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

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"
})();

Readme

Keywords

none

Package Sidebar

Install

npm i json-configuration-parser

Weekly Downloads

1

Version

0.1.3

License

ISC

Unpacked Size

21.2 kB

Total Files

13

Last publish

Collaborators

  • eiwosstd