2.0.1 • Published 2 months ago

dotenvguard v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

dotenvguard

Discord Twitter MIT License


Installation

npm

$ npm install dotenvguard

yarn

$ yarn add dotenvguard

pnpm

$ pnpm add dotenvguard

Usage

  • Basic usage (warning mode only)
import { envguard } from 'dotenvguard';

/**
 * @param key - The key to check in the environment variables.
 */
envguard('MY_TEST_KEY');
Warning: The key is missing or empty in .env file: MY_STRICT_KEY
  • Advanced usage (error mode)
import { envguard } from 'dotenvguard';

/**
 * @param key - The key to check in the environment variables. 
 * @param strict - Enabled strict mode
 */
envguard({ strict: ["MY_STRICT_KEY"] })
C:\XXX\XXX\XXX\XXX.js:41
            throw new Error(errorMessage);
            ^

Error: Required key missing or empty in .env file: MY_STRICT_KEY

Utility

import { envinfo } from 'dotenvguard';

console.log(envinfo()); // { exists: boolean }

```ts
import { envinfo } from 'dotenvguard';

console.log(envinfo('advanced')); 
// -- General information --
// - Current working directory: C:\XXX\XXX\XXX\XXX\dotenvguard
// - .env working directory: C:\XXX\XXX\XXX\XXX\dotenvguard

// -- ENV file information --
// - Created by: XXX
// - Created at: 2024-03-23T00:33:42.807Z
// - Updated at: 2024-03-23T00:33:42.807Z

// -- Logging time --
// - Logged time: 2024-03-23T00:37:14.207Z
// - User: XXX
// {
//   exists: true,
//   path: 'C:\\XXX\\XXX\\XXX\\XXX\\dotenvguard\\.env',
//   createdAt: 2024-03-23T00:33:42.807Z,
//   updatedAt: 2024-03-23T00:33:42.807Z
// }

Remember

  • Throws error if .env has not been found (any mode)
C:\XXX\XXX\XXX\XXX.js:41
        throw new Error(colors_1.default.red('.env file not found'));
        ^

Error: .env file not found
2.0.1

2 months ago

2.0.0

2 months ago

1.3.5

1 year ago

1.3.0

1 year ago

1.2.5

1 year ago

1.2.0

1 year ago