node console.log / util.inspect for nested Object / Array
javascript, node.js
Solution
`util.inspect()` takes a second `options` argument, where you can specify `depth`. The default is 2.
http://nodejs.org/api/util.html#util_util_inspect_object_options
So:
util = require('util');
var obj = { foo: { foo: { foo: { foo: { foo: { foo: 'foo' } } } } } };
console.log(util.inspect(obj, {depth:12}));
... yields:
{ foo: { foo: { foo: { foo: { foo: { foo: 'foo' } } } } } }
Problem
For the nested Object or Array ``` var obj = { foo: { foo: { foo: { foo: { foo: { foo: 'foo' } } } } } }; console.log(obj); util.debug(obj); util.debug(util.inspect(obj)); ``` The `console.log` or `util.debug` + `util.inspect` ``` { foo: { foo: { foo: [Object] } } } DEBUG: [object Object] DEBUG: { foo: { foo: { foo: [Object] } } } ``` Under a certain depth, it shows just `[Object]` with no further detail. This is always annoying on debugging since I can't investigate the actual value. Why does `node` (or V8) implements like this? and Is there any work-around? Thanks. EDIT: I received a suggestion `console.log(JSON.stringify(obj));` The result `{"foo":{"foo":{"foo":{"foo":{"foo":{"foo":"foo"}}}}}}` It sort of works, but obviously the whole is `stringify`ed, and probably I couldn't do this for all object output on debugging. Not generic method. EDIT2: solution: `console.log(util.inspect(obj,{ depth: null }));` output: `{ foo: { foo: { foo: { foo: { foo: { foo: 'foo' } } } } } }` cool. This is what I want!