Although dotenv is reliable, it may not be necessary or may lack certain features.
Modern and secure alternative by the same author. It supports encryption, and multi-environment configs.
Built into Node.js since v20.6.0 (v22.9.0 for --env-file-if-exists
). Zero dependencies, good for simple use cases.
--env-file
will raise an error if the env-file does not exist. For those cases, where the env-file might or might not exist, use --env-file-if-exists
.
node --env-file=.env index.js
Also supported by tsx, Bun, and Deno.
Node docs: --env-file
/ --env-file-if-exists