dotenv
- Version 17.2.3
- Published
- 82.4 kB
- No dependencies
- BSD-2-Clause license
Install
npm i dotenvyarn add dotenvpnpm add dotenvOverview
Loads environment variables from .env file
Index
Functions
function config
config: (options?: DotenvConfigOptions) => DotenvConfigOutput;Loads
.envfile contents into process.env by default. IfDOTENV_KEYis present, it smartly attempts to load encrypted.env.vaultfile contents into process.env.See https://dotenvx.com/docs
Parameter options
additional options. example:
{ path: './custom/path', encoding: 'latin1', quiet: false, debug: true, override: false }Returns
an object with a
parsedkey if successful orerrorkey if an error occurred. example: { parsed: { KEY: 'value' } }
function configDotenv
configDotenv: (options?: DotenvConfigOptions) => DotenvConfigOutput;Loads
.envfile contents into process.env.See https://dotenvx.com/docs
Parameter options
additional options. example:
{ path: './custom/path', encoding: 'latin1', quiet: false, debug: true, override: false }Returns
an object with a
parsedkey if successful orerrorkey if an error occurred. example: { parsed: { KEY: 'value' } }
function decrypt
decrypt: (encrypted: string, keyStr: string) => string;Decrypt ciphertext
See https://dotenvx.com/docs
Parameter encrypted
the encrypted ciphertext string
Parameter keyStr
the decryption key string
Returns
{string}
function parse
parse: <T extends DotenvParseOutput = DotenvParseOutput>( src: string | Buffer) => T;Parses a string or buffer in the .env file format into an object.
See https://dotenvx.com/docs
Parameter src
contents to be parsed. example:
'DB_HOST=localhost'Returns
an object with keys and values based on
src. example:{ DB_HOST : 'localhost' }
function populate
populate: ( processEnv: DotenvPopulateInput, parsed: DotenvPopulateInput, options?: DotenvConfigOptions) => DotenvPopulateOutput;Loads
sourcejson contents intotargetlike process.env.See https://dotenvx.com/docs
Parameter processEnv
the target JSON object. in most cases use process.env but you can also pass your own JSON object
Parameter parsed
the source JSON object
Parameter options
additional options. example:
{ quiet: false, debug: true, override: false }Returns
an object with the keys and values that were actually set
Interfaces
interface DotenvConfigOptions
interface DotenvConfigOptions {}property debug
debug?: boolean;Default:
falseTurn on logging to help debug why certain keys or values are not being set as you expect.
example:
require('dotenv').config({ debug: process.env.DEBUG })
property DOTENV_KEY
DOTENV_KEY?: string;Default:
undefinedPass the DOTENV_KEY directly to config options. Defaults to looking for process.env.DOTENV_KEY environment variable. Note this only applies to decrypting .env.vault files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a .env file.
example:
require('dotenv').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenvx.com/vault/.env.vault?environment=production' })
property encoding
encoding?: string;Default:
utf8Specify the encoding of your file containing environment variables.
example:
require('dotenv').config({ encoding: 'latin1' })
property override
override?: boolean;Default:
falseOverride any environment variables that have already been set on your machine with values from your .env file.
example:
require('dotenv').config({ override: true })
property path
path?: string | string[] | URL;Default:
path.resolve(process.cwd(), '.env')Specify a custom path if your file containing environment variables is located elsewhere. Can also be an array of strings, specifying multiple paths.
example:
require('dotenv').config({ path: '/custom/path/to/.env' })example:require('dotenv').config({ path: ['/path/to/first.env', '/path/to/second.env'] })
property processEnv
processEnv?: DotenvPopulateInput;Default:
process.envSpecify an object to write your secrets to. Defaults to process.env environment variables.
example:
const processEnv = {}; require('dotenv').config({ processEnv: processEnv })
property quiet
quiet?: boolean;Default:
falseSuppress all output (except errors).
example:
require('dotenv').config({ quiet: true })
interface DotenvConfigOutput
interface DotenvConfigOutput {}interface DotenvParseOutput
interface DotenvParseOutput {}index signature
[name: string]: string;interface DotenvPopulateInput
interface DotenvPopulateInput {}index signature
[name: string]: string;interface DotenvPopulateOptions
interface DotenvPopulateOptions {}property debug
debug?: boolean;Default:
falseTurn on logging to help debug why certain keys or values are not being set as you expect.
example:
require('dotenv').config({ debug: process.env.DEBUG })
property override
override?: boolean;Default:
falseOverride any environment variables that have already been set on your machine with values from your .env file.
example:
require('dotenv').config({ override: true })
interface DotenvPopulateOutput
interface DotenvPopulateOutput {}index signature
[name: string]: string;Type Aliases
type DotenvError
type DotenvError = Error & { code: | 'MISSING_DATA' | 'INVALID_DOTENV_KEY' | 'NOT_FOUND_DOTENV_ENVIRONMENT' | 'DECRYPTION_FAILED' | 'OBJECT_REQUIRED';};Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (7)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/dotenv.
- Markdown[](https://www.jsdocs.io/package/dotenv)
- HTML<a href="https://www.jsdocs.io/package/dotenv"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3685 ms. - Missing or incorrect documentation? Open an issue for this package.
