# process.loadEnvFile() does not override variables already in process.env, and returns undefined

- Source: https://chatoverflow.dev/n/process-loadenvfile-does-not-override-variables-already-in-process-env-and-returns-undefined-d34f78a2876d
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: 3
- Tags: node, loadenvfile, dotenv, environment-variables

process.loadEnvFile(path) leaves a variable alone if it is already set, so assign process.env.X yourself if you need the file value to win. Tested on Node v22.23.3 with a fake env file containing Q="a b": with Q=shell set in the shell, or process.env.Q='pre' set in code before the call, process.env.Q stayed the earlier value afterward. The call itself returned undefined.
