A Python library that loads key-value pairs from a .env file into environment variables, following 12-factor app practices.
motdotla/dotenv
A zero-dependency Node.js module that loads environment variables from a .env file into process.env.
- Stars
- 20,561
- Forks
- 983
- Open issues
- 1
- Last commit
- 8 days ago
What is it?
dotenv loads key-value pairs from a .env file into process.env in Node.js applications, so configuration and secrets can live outside source code, following the Twelve-Factor App approach. A project creates a .env file at its root, calls config() as early as possible, and then reads values through process.env as usual.
Beyond the core loader, the package exposes parse() to turn a string or Buffer into an object, and populate() to write parsed values into any target object. It also ships a dotenv CLI with a run subcommand that injects variables before starting a command, supporting multiple files, override and quiet flags, and a faster parser option.
The package has no dependencies and works with npm, yarn, pnpm, bun and deno. Variable expansion, command substitution and encryption are not part of this package; the README points to the companion tool dotenvx for those features.
Key features
- 01Loads .env key-value pairs into process.env with a single config() call.
- 02Provides parse() to convert a string or Buffer into an object.
- 03Provides populate() to write values into a custom target object.
- 04Includes a CLI with dotenv run to inject variables before running a command.
- 05Supports multiple env files loaded in order, with optional override.
- 06Has zero dependencies and works with ESM imports via dotenv/config.
Use cases
- Keeping API keys and database URLs out of source code in a Node.js service.
- Using different .env files for local, test and production environments.
- Injecting environment variables into test commands or scripts with dotenv run.
- Parsing env-formatted text in a custom tool through the parse() function.
Quick start
- 1
Install dotenv with npm
npm install dotenv --save - 2
Create a .env file in your project root with your variables
- 3
Load dotenv at the start of your application
- 4
Run your app with node
node index.js
Things to know
- Variable expansion and command substitution require the separate dotenvx tool.
- Comments start at # unless the value is quoted, which is a breaking change from v15.
In collections
Topics
FAQ
- What is dotenv?
- A zero-dependency Node.js module that loads environment variables from a .env file into process.env. dotenv loads key-value pairs from a .env file into process.env in Node.js applications, so configuration and secrets can live outside source code, following the Twelve-Factor App approach. A project creates a .env file at its root, calls config() as early as possible, and then reads values through process.env as usual.
- Is dotenv free to use? What license does it have?
- dotenv is open source under the BSD-2-Clause license. Check the license terms before using it in commercial products.
- Is dotenv still maintained?
- Actively maintained. The last commit to dotenv was on Oct 29, 2026.
- What can I use dotenv for?
- Keeping API keys and database URLs out of source code in a Node.js service. Using different .env files for local, test and production environments. Injecting environment variables into test commands or scripts with dotenv run. Parsing env-formatted text in a custom tool through the parse() function.
- How do I install dotenv?
- Install dotenv with npm: npm install dotenv --save Create a .env file in your project root with your variables Load dotenv at the start of your application Run your app with node: node index.js
- Where can I get dotenv?
- The source code and installation instructions are on GitHub: https://github.com/motdotla/dotenv
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Open-source secrets and environment variable manager with a web dashboard, a CLI, and GitHub Actions sync.
A zero-dependency Go library that parses environment variables into typed structs using struct tags.
A single Rust CLI that installs project tools, sets environment variables, and runs tasks from one mise.toml file.
A one-command CLI that rates how exposed a shipped app's build output is to AI reverse-engineering agents like rea, and fixes what it safely can.
A self-contained, themeable tmux configuration with a Powerline-style status line, mouse mode, clipboard integration and TPM plugin support.