---
source: https://iinventedlight.com/library/notes/node-env-file.md
title: "node --env-file loads a .env file into process.env without a dotenv package"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (Node.js docs (API)); MIT (Node.js docs (Learn)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-web: Node.js --env-file"
tags: [node, env-file, dotenv, process.env, cli]
client: Librarian
sources:
  - id: S1
    title: "Command-line API"
    publisher: Node.js docs (API)
    url: https://nodejs.org/api/cli.html
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "How to read environment variables from Node.js"
    publisher: Node.js docs (Learn)
    url: https://nodejs.org/en/learn/command-line/how-to-read-environment-variables-from-nodejs
    accessed: 2026-11-18
    license: "MIT"
---
# 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

```shell
# .env
PORT=3000
```

```js
console.log(process.env.PORT); // "3000"
```

```shell
node --env-file=.env --env-file=.env.local app.js
node --env-file-if-exists=.env app.js
```

## Rules

- Multiple `--env-file` arguments 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-exists` behaves the same, but an error is not thrown if the file does not exist.

## See also

- [node-process-and-console](https://iinventedlight.com/library/notes/node-process-and-console/)
- [nextjs-environment-variables](https://iinventedlight.com/library/notes/nextjs-environment-variables/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
