dotenvguard
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

dotenvguard

Discord Twitter MIT License

An up-2-date guard for your environment variables.

dotenvguard


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 }
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

Package Sidebar

Install

npm i dotenvguard

Weekly Downloads

4

Version

2.0.1

License

MIT

Unpacked Size

12.7 kB

Total Files

9

Last publish

Collaborators

  • vkxni