process.env
process.env is the object that holds every environment variable of the running process.
In this page:
Syntax
process.env.KEY
process.env.NODE_ENV
process.env
Every value is a string, and missing ones are undefined. NODE_ENV is a convention that toggles production behaviour in many libraries. Assigning to process.env converts the value to a string.
Note:
Setting NODE_ENV=production speeds up frameworks such as Express.
Example: process.env
process.env.RETRIES = 3;
console.log(typeof process.env.RETRIES, process.env.RETRIES);
console.log(process.env.NOT_SET);
console.log(process.env.NOT_SET ?? "default value");
console.log("PATH is set:", typeof process.env.PATH === "string");
// Output:
// string 3
// undefined
// default value
// PATH is set: true
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
Common Mistakes
- Assuming values are numbers or booleans
- Relying on undefined variables
- Setting NODE_ENV inconsistently
Chapter Summary
- Values are strings
- Missing means undefined
- NODE_ENV=production changes behaviour
- Assignments become strings
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: