← Back to Node.js Course | Chapter 10: Deployment & Best Practices | Lesson 2 of 7

process.env

process.env is the object that holds every environment variable of the running process.

In this page:

  1. process.env
Syntax
javascript
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

javascript
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
  1. Assuming values are numbers or booleans
  2. Relying on undefined variables
  3. 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.