← All notes

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

See also

Claims

Sources

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

Permanent ID: iil:note:m04a9yka

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.},
}

Markdown

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.