node --env-file loads a .env file into process.env without a dotenv package
Answer: Run node --env-file=.env app.js. The flag loads environment variables from a file relative to the current directory, making them available on process.env. It was added in v20.6.0 and is no longer experimental since v24.10.0 and v22.21.0.
Example
# .env
PORT=3000
console.log(process.env.PORT); // "3000"
node --env-file=.env --env-file=.env.local app.js
node --env-file-if-exists=.env app.js
Rules
- Multiple
--env-filearguments are allowed; variables defined in previous files are overridden by subsequent files. - Environment variables that configure Node.js, such as
NODE_OPTIONS, are parsed and applied from the file. - Multi-line values are supported since v21.7.0 and v20.12.0.
--env-file-if-existsbehaves the same, but an error is not thrown if the file does not exist.
See also
Claims
- id: C1 claim: --env-file loads variables onto process.env. source: S1 evidence: "Loads environment variables from a file relative to the current directory"
- id: C2 claim: --env-file was added in v20.6.0. source: S1 evidence: "--env-file=file # Added in: v20.6.0"
- id: C3 claim: The flag is no longer experimental. source: S1 evidence: "The --env-file flag is no longer experimental."
- id: C4 claim: Later env files override earlier ones. source: S2 evidence: "Subsequent files override pre-existing variables defined in previous"
Sources
- [S1] Command-line API. Node.js docs (API). https://nodejs.org/api/cli.html . License: MIT. Accessed 2026-11-18.
- [S2] How to read environment variables from Node.js. Node.js docs (Learn). https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Command-line API; Node.js docs (Learn), How to read environment variables from Node.js. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Node.js docs (API), Command-line API; Node.js docs (Learn), How to read environment variables from Node.js. MIT (https://raw.githubusercontent.com/nodejs/node/main/LICENSE). Copyright Node.js contributors.
Cite this
iinventedlight. 2026. "node --env-file loads a .env file into process.env without a dotenv package." iinventedlight Library, iil:note:m04a9yka, version of 2026-11-18. https://iinventedlight.com/library/notes/node-env-file/. License: CC-BY-4.0.
@misc{iil_note_m04a9yka,
author = {{iinventedlight}},
title = {{node --env-file loads a .env file into process.env without a dotenv package}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/node-env-file/},
note = {Permanent ID iil:note:m04a9yka. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/node-env-file.md.