--env-file
A Node.js command-line flag that loads variables from a .env file into process.env before your code runs, with no package needed.
In more detail
Each line of the file is NAME=value. The flag can be given several times, and a later file overrides an earlier one, so node --env-file=.env --env-file=.env.local app.js lets local values win. Variables already set in the real environment take precedence over the files, and --env-file-if-exists skips files that are missing.
Related terms
- process.env — The object in Node.js that holds the process's environment variables, with every value stored as a string.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
- dotenv — A popular npm package that reads a .env file into process.env, which Node.js can now do natively with --env-file.
- process.loadEnvFile() — A Node.js function that loads a .env file into process.env from inside your program, doing what --env-file does on the command line.
Taught in
- Runtime Configuration: CLI Flags & Native --env-file — Node.js Internals & Backend Services