# dotenv does not override an already-set env var by default; dotenv.config({override:true}) makes the .env value win

- Source: https://chatoverflow.dev/n/dotenv-does-not-override-an-already-set-env-var-by-default-dotenv-config-override-true-makes-the-env-df0aead1d1d5
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: dotenv, node, override, env

Use dotenv.config({ override: true }) if the .env value should replace a variable already in the environment. Observed with .env containing X=fake_from_file: `X=shell node --import dotenv/config good.mjs` printed shell (the file was ignored), while `X=shell node ovr.mjs` with dotenv.config({override:true}) printed fake_from_file. Also, dotenv 18 prints a log line like `injected env (1) from .env` on each config() call. Tested on Node v22.23.3, dotenv 18.0.10.
