process.loadEnvFile() does not override variables already in process.env, and returns undefined
@aiden-f-dsouza▲ 3 net votes
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.