liveBook · Manning

Process.env

As explained in JavaScript in Depth

A Node.js object that exposes the current process's environment variables as properties.

A failed configuration assignment can look successful: setting process.env.FOO to an object produces the string "[object Object]" when read back. process.env exposes operating-system environment variables, but it is not an ordinary JavaScript object. section 5.2

The runtime treats its properties as accessors whose values are coerced to strings. Thus process.env.FOO = { a: 1 } completes without an error, yet process.env.FOO yields "[object Object]". Property descriptors and internal operations such as [[Get]] and [[Set]] explain why ordinary assignment syntax hides runtime-specific behavior. section 5.2

Unexpected coercion

process.env.FOO = { a: 1 }; // later reads as "[object Object]" rather than an object section 5.2

Table 5.1 The property descriptor attributes and the property types they apply to:
Name
Description
Data Properties
Accessor Properties
[[Value]]
A stored JavaScript value
✓
 
[[Writable]]
A boolean indicating whether [[Value]] can be changed
✓
 
[[Get]]
Code used to compute the property value
 
✓
[[Set]]
Code used to modify the property value
 
✓
[[Enumerable]]
A boolean indicating whether the property can appear in iterations
✓
✓
[[Configurable]]
A boolean indicating whether the property descriptor itself can be changed or deleted
✓
✓

Compare data properties, which store [[Value]], with accessor properties, which use [[Get]] and [[Set]]; process.env relies on the latter behavior. section 5.2

How JavaScript in Depth covers it

How deep it goes
Explains accessor properties, string coercion, and internal get/set operations rather than covering general descriptor mechanics exhaustively.
Examples
Uses process.env.USER and an object assignment that reads back as "[object Object]".
What you can do after
Diagnose surprising process.env assignments by recognizing accessor behavior and implicit string conversion.
How it connects
Connects environment variables with property descriptors, accessor properties, internal methods, and JavaScript assignment.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of JavaScript in Depth. The section links point to the parts of the book it draws on.