When debugging using console.log()
, how can I get the full object?
const myObject = {
\"a\":\"a\",
\"b\":{
\"c\":\"c\",
\"d\":
A good way to inspect objects is to use node --inspect option with Chrome DevTools for Node.
node.exe --inspect www.js
Open chrome://inspect/#devices
in chrome and click Open dedicated DevTools for Node
Now every logged object is available in inspector like regular JS running in chrome.
There is no need to reopen inspector, it connects to node automatically as soon as node starts or restarts. Both --inspect and Chrome DevTools for Node may not be available in older versions of Node and Chrome.
Easiest option:
console.log('%O', myObject);
Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:
require("util").inspect.defaultOptions.depth = null;
console.log(myObject);
You need to use util.inspect()
:
const util = require('util')
console.log(util.inspect(myObject, {showHidden: false, depth: null}))
// alternative shortcut
console.log(util.inspect(myObject, false, null, true /* enable colors */))
Outputs
{ a: 'a', b: { c: 'c', d: { e: 'e', f: { g: 'g', h: { i: 'i' } } } } }
See util.inspect() docs.
Try this:
console.dir(myObject,{depth:null})
If you're looking for a way to show the hidden items in you array, you got to pass maxArrayLength: Infinity
console.log(util.inspect(value, { maxArrayLength: Infinity }));