Inspect an object with console.dir
Show nested objects beyond the default depth of two with console.dir and the depth option, instead of the [Object] placeholders console.log prints.
console.log stops after two levels of nesting and prints [Object] for anything deeper. console.dir lets you choose the depth.
const config = { a: { b: { c: { d: 1 } } } };
console.log(config);
console.dir(config, { depth: null });{ a: { b: { c: [Object] } } }
{
a: { b: { c: { d: 1 } } }
}depth: null means unlimited. A number such as depth: 4 is safer for huge objects. The option list matches util.inspect, so colors: true and showHidden: true also work. See console.dir.
The second output breaks into lines because Node.js only joins up to three nested levels on one line. That is formatting, not a change in the data.
In a browser, console.dir shows an expandable tree, which is more useful for DOM elements than console.log, since log prints them as markup. The depth option applies to Node.js; browsers ignore it.
Beware of circular references: they print as [Circular *1] instead of looping.