Load environment variables from a .env file into process.env in Node.js
open sourceBSD-2-Clausefree
dotenv is a zero-dependency Node.js module that loads environment variables from a .env file into process.env, so configuration lives outside the code. Call it as early as possible in your app, or use the dotenv command that comes with the package to load one or more files and then run any command with those variables. It supports multiline values and comments, can load several files with later or earlier values winning, can override existing variables, and has parse and populate functions for custom use. For variable expansion, command substitution and encrypted .env files its README points to dotenvx.
Problems it solves
- load settings from a .env file in my Node.js app
- keep API keys out of my JavaScript source code
- run a command with variables from .env without exporting them by hand
Features
- Loads .env files into process.env with no dependencies
- dotenv run CLI loads env files and runs a command
- Multiple files, with override and precedence options
- Multiline values and comments
- Parse and populate functions for custom loading
Limitations
- Variable expansion, command substitution and encryption aren't built in: its makers point to dotenvx for those1
Alternatives
The same job
These do what dotenv does.
