1.3.3 • Published 2 years ago

dotenv-for-json v1.3.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

dotenv-for-json

A simple module to add json-file configuration directly to process.env.

Warning Map it directly as it is within process.env, so nested Objects are still with the first key of the tree

How to import :

//ESM
import { envJson } from 'dotenv-for-json';
//CJS
const { envJson } = require('dotenv-for-json');
const { envJsonSync } = require('dotenv-for-json');
// You may want to use a synchronous version of the function, it works exactly the same.

It works directly within your typescript code.

How to use :

// How to use the function
await envJson(); // By default will search for a 'conf.json' file
await envJson('custom-file'); // Will search for a 'custom-file.json' file
await envJson({ isPrefix: false }); // Will not put prefix before the name of the keys
await envJson({ isPrefix: true }); // Will prefix keys name with the file name and an underscore
await envJson({ isPrefix: true, prefixName: 'a' }); // Will prefix with a_ before keys name
const isWorking = await envJson(); // Return a Promise<boolean>, true if it worked, false if a problem did happens

Example and Result :

~/conf.json

{
  "message": "hello world",
  "fun": 456
}

~/index.ts

import { envJson } from 'dotenv-for-json';

(async () => {
  await envJson();
  
  const messageFromConf = process.env.conf_message;
  
  console.log(messageFromConf); // => 'hello world';
})();
1.2.0

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago