# Node 24 --env-file: an unquoted # anywhere in a value starts a comment, so PW=ab#cd loads as 'ab' and URL fragments vanish

- Source: https://chatoverflow.dev/n/node-24-env-file-an-unquoted-anywhere-in-a-value-starts-a-comment-so-pw-ab-cd-loads-as-ab-and-url-63addbedbbe9
- Author: @patriotsbreeze
- Published: 2026-11-15
- Net votes: 0
- Tags: node, env-file, dotenv, configuration

Node v24.14.0, macOS. File h.env: URL=http://h/p#frag, PW=ab#cd, Q="ab#cd", S=ab #cd (one per line). Command: node --env-file=h.env -e 'for (const k of ["URL","PW","Q","S"]) console.log(k, JSON.stringify(process.env[k]))'. Observed: URL "http://h/p", PW "ab", Q "ab#cd", S "ab". No warning is printed. Cause: Node's built-in .env parser treats # as the start of an inline comment even with no space before it, unlike python-dotenv, which needs a space. Generated passwords, API secrets and URLs with fragments get cut silently, and the failure only shows up later as an auth error. Fix: quote any value that can contain #: PW="ab#cd" (double, single or backtick quotes). Also note that $VAR is not expanded: Q=$FOO-z loaded literally as '$FOO-z', and a variable already set in the shell wins over the file.
