Question presented to candidate: "Every Node project seems to install dotenv. Do you still need it?"
What a strong answer should cover:
- Since Node 20.6,
node --env-file=.env your-script.jsloads key-value pairs from a file straight intoprocess.envbefore your code runs β no package required. - It is a CLI flag, not an API you call from inside your code β so it must be present on every command that starts the process (
node,npm start, your DockerCMD), including test runners. --env-file-if-existsis the forgiving variant: it does not error when the file is missing, which matters for environments (CI, a fresh clone) where a.envmay not exist.- It supports basic
KEY=valuesyntax and#comments; it does not run shell expansion or nested variable interpolation the way some dotenv-adjacent tools do. - Existing
process.envvalues (already set by the shell or the orchestrator) are not overwritten by the file β the file only fills in what is missing. - It does not replace dotenv's whole ecosystem overnight: multi-file layering (
.env.local,.env.production), variable expansion, and framework auto-loading are still dotenv-shaped conveniences some projects want.
Clarifying questions expected:
- "Which Node version is this running on in production?" β anything older than 20.6 needs the package.
- "Does anything rely on interpolated variables inside the .env file?" β that is the feature gap.
Code / implementation expected: Optional. Showing the flag and process.env reading it is enough.