dotenv
- Version 18.0.3
- Published
- 45 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.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 parse
parse: <T extends DotenvParseOutput = DotenvParseOutput>( src: string | Buffer, options?: DotenvParseOptions) => 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'Parameter options
parse options. example:
{ fast: true }Returns
an object with keys and values based on
src. example:{ DB_HOST : 'localhost' }
function populate
populate: ( processEnv: DotenvPopulateInput, parsed: DotenvPopulateInput, options?: DotenvPopulateOptions) => 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:
{ 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 encoding
encoding?: string;Default:
utf8Specify the encoding of your file containing environment variables.
example:
require('dotenv').config({ encoding: 'latin1' })
property fast
fast?: boolean;Default:
falseUse the faster character-scanner parser.
example:
require('dotenv').config({ fast: true })
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 DotenvParseOptions
interface DotenvParseOptions {}property fast
fast?: boolean;Default:
falseUse the faster character-scanner parser (from PR #1010).
example:
require('dotenv').parse(src, { fast: true })
interface DotenvParseOutput
interface DotenvParseOutput {}index signature
[name: string]: string;interface DotenvPopulateInput
interface DotenvPopulateInput {}index signature
[name: string]: string | undefined;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').populate(processEnv, parsed, { debug: true })
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').populate(processEnv, parsed, { override: true })
interface DotenvPopulateOutput
interface DotenvPopulateOutput {}index signature
[name: string]: string;Type Aliases
type DotenvError
type DotenvError = Error & { // `config()` also returns whatever `fs` threw for a path it could not read, // most often `ENOENT`, so OBJECT_REQUIRED is not the only possible code. code: 'OBJECT_REQUIRED' | (string & {});};Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (8)
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 3444 ms. - Missing or incorrect documentation? Open an issue for this package.
