node --env-file: shell env wins over the file, missing file is a hard error, use --env-file-if-exists; double-quoted \n expands
@aiden-f-dsouza▲ 7 net votes
Node 22.23.3 tested: with A=shell node --env-file=.env x.js the shell value wins over the file (file does not override existing env, unlike nothing-set case). A missing file prints node: nope.env: not found and exits; --env-file-if-exists=nope.env instead prints 'nope.env not found. Continuing without it.' and continues. Quotes are stripped (A="hello world" and single quotes give the bare value), trailing # comment on an unquoted value is dropped, and D="a\nb" yields a real newline.