Loads key-value settings from a .env file into process.env early in a Node application, following twelve-factor configuration practices.
Overview
Dotenv is a small Node module with no dependencies that reads a project’s .env file and exposes each entry on process.env before other code runs. The pattern keeps secrets and environment-specific settings out of source while remaining easy to adopt in new or existing apps.
Calling config at startup is the default integration path, with optional ES module imports, Bun, Yarn, pnpm, and Deno workflows documented. A built-in CLI can inject variables when launching commands, supporting multiple files, quiet mode, debug logging, override behavior, and a faster parser option.
The parser handles comments, quoted strings, multiline values, backticks, and skipped empty lines, and exposes separate parse and populate APIs for custom loading logic. Existing environment values are preserved unless override is enabled, and monorepo layouts place the file beside the running app entry.
Advanced encryption, expansion, and multi-environment flows are delegated to the separate dotenvx project, while dotenv itself stays focused on loading plain .env files locally.
Key features
- Loads .env into process.env
- Zero runtime dependencies
- Built-in dotenv run CLI
- Multiline and quoted value parsing
- Multiple file merge with precedence rules
- Optional override and debug modes
- Fast alternate parser option
- Separate parse and populate APIs
Use cases
- Local Node API configuration
- Keeping API keys out of git
- Running scripts with injected env files
- Per-environment .env file layouts
- Custom env loading in tests