None of the 7 prior answers mentioned that console.dir
supports extra arguments: depth
, showHidden
, and whether to use colors
.
Of particular interest is depth
, which (in theory) allows travering objects into more than the default 2 levels that console.log
supports.
I wrote "in theory" because in practice when I had a Mongoose object and ran console.log(mongoose)
and console.dir(mongoose, { depth: null })
, the output was the same. What actually recursed deeply into the mongoose
object was using util.inspect
:
import * as util from 'util';
console.log(util.inspect(myObject, {showHidden: false, depth: null}));