process.env
An object containing the user environment variables.
Syntax
process.env Returns
object<string, string> — Environment variable names mapped to string values.
Examples
const port = process.env.PORT ?? '3000';
console.log(`listening on ${port}`);
Output
listening on 3000
if (process.env.NODE_ENV === 'production') {
console.log('prod mode');
} else {
console.log('dev mode');
}
Output
dev mode
Notes
Every value is a string, so `process.env.DEBUG === 'true'` not a
boolean. Assigning to `process.env` mutates the process environment.
Never commit secrets; load them from a `.env` file (Node 20.6+
supports `--env-file`). Reading a missing var returns `undefined`.