dotenv
dotenv is the library and convention that loads .env files into environment variables; it is the most popular in the Node.js ecosystem and externalizes configuration.
Purpose
To let local development manage configuration with a .env file while production uses real environment variables, without code changes.
Mechanism
At startup it reads the .env file, parses KEY=VALUE lines, and injects them into process.env. It supports multiple environments (.env.development), variable interpolation ($VAR), and quote handling. It does not override existing environment variables (unless override is set).
Use cases
- Local configuration for Node.js projects
- Next.js/Vite environment variables
- Docker Compose env_file
- Test environment isolation
Examples
- Input
.env: API_KEY=secretOutputprocess.env.API_KEY="secret"Loaded into the environment
Common errors
- Loading dotenv in production wastes startup time
- Use real environment variables in production and do not load .env
Related terms
ENV
An ENV file defines environment variables in KEY=VALUE format for application configuration; it is the recommended approach of 12-factor apps. GLOSSARY
INI
INI is a traditional configuration file format that groups settings with [section] headers and key=value pairs; it is simple but unstandardized, and implementations differ slightly. GLOSSARY
Properties
Java Properties files use KEY=VALUE or KEY:VALUE format; they are the traditional configuration format of the Java ecosystem and support Unicode escapes. GLOSSARY
Related tools
ENV Parser
Parse .env-style KEY=VALUE lines into JSON. Blank lines and #-prefixed comments are skipped. dotenv conventions beyond that are not implemented: an "export " prefix stays in the key (export PORT=3000 → "export PORT"), and quotes around values are kept verbatim. TOOL
ENV Stringify
ENV Stringify — pure client-side tool. Privacy-first, no server round-trip. TOOL
Json To Env
Json To Env — pure client-side tool. Privacy-first, no server round-trip. TOOL
Yaml To Env
Yaml To Env — pure client-side tool. Privacy-first, no server round-trip. TOOL