How motdotla/dotenv works
dotenv loads key/value settings from .env files into a process environment, either through its JavaScript API or by launching a command with the CLI. The core path covers file parsing, option resolution, and environment population; the CLI separately resolves run arguments and starts a child process. The README also documents preload imports and multiple-file loading. Source excerpts show the principal calls; README-described behavior is cited where implementation details were not sampled.
Main entry points: main.js dotenv API · cli.js CLI Entry · config.js Preload Entry · spawn-command.js Command Launcher
Components 14
Environment API
- dotenv API
lib/main.js - Env Parser
lib/main.js - Env Population
lib/main.js - Process Environment
- Preload Entry
config.js
Command Runner
- CLI Entry
cli.js - Run Options
cli.js - CLI Env Loader
cli.js - Command Launcher
lib/spawn-command.js
Configuration
- Env Option Resolver
lib/config-options.js
Other components
- Application
- CLI User
- .env Files
- Child Command
Connections 19
- Application → dotenv API: calls config
README.md - Application → Preload Entry: imports preload
README.md - Preload Entry → dotenv API: configures
config.js - dotenv API → Env Parser: parses contents
lib/main.js - dotenv API → Env Population: populates values
lib/main.js - Env Parser → Env Population: provides parsed values
lib/main.js - dotenv API → .env Files: reads files
lib/main.js - Env Population → Process Environment: writes values
lib/main.js - dotenv API → Env Option Resolver: resolves env options
lib/main.js - CLI User → CLI Entry: runs command
cli.js - CLI Entry → Run Options: resolves arguments
cli.js - Run Options → Env Option Resolver: reads defaults
cli.js - CLI Entry → CLI Env Loader: loads settings
cli.js - CLI Env Loader → .env Files: reads files
cli.js - CLI Env Loader → dotenv API: uses parse and populate
cli.js - CLI Env Loader → Process Environment: injects values
cli.js - CLI Entry → Command Launcher: launches command
cli.js - Command Launcher → Child Command: spawns process
lib/spawn-command.js - Process Environment → Child Command: inherited by
README.md