How can I get the full object in Node.js's console.log(), rather than '[Object]'?












660















When debugging using console.log(), how can I get the full object?



const myObject = {
"a":"a",
"b":{
"c":"c",
"d":{
"e":"e",
"f":{
"g":"g",
"h":{
"i":"i"
}
}
}
}
};
console.log(myObject);


Outputs:



{ a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }


But I want to also see the content of property f.










share|improve this question





























    660















    When debugging using console.log(), how can I get the full object?



    const myObject = {
    "a":"a",
    "b":{
    "c":"c",
    "d":{
    "e":"e",
    "f":{
    "g":"g",
    "h":{
    "i":"i"
    }
    }
    }
    }
    };
    console.log(myObject);


    Outputs:



    { a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }


    But I want to also see the content of property f.










    share|improve this question



























      660












      660








      660


      198






      When debugging using console.log(), how can I get the full object?



      const myObject = {
      "a":"a",
      "b":{
      "c":"c",
      "d":{
      "e":"e",
      "f":{
      "g":"g",
      "h":{
      "i":"i"
      }
      }
      }
      }
      };
      console.log(myObject);


      Outputs:



      { a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }


      But I want to also see the content of property f.










      share|improve this question
















      When debugging using console.log(), how can I get the full object?



      const myObject = {
      "a":"a",
      "b":{
      "c":"c",
      "d":{
      "e":"e",
      "f":{
      "g":"g",
      "h":{
      "i":"i"
      }
      }
      }
      }
      };
      console.log(myObject);


      Outputs:



      { a: 'a', b: { c: 'c', d: { e: 'e', f: [Object] } } }


      But I want to also see the content of property f.







      javascript node.js debugging console.log






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 15 '16 at 9:51









      Michał Perłakowski

      45.1k16105122




      45.1k16105122










      asked May 23 '12 at 23:29







      user1372449































          13 Answers
          13






          active

          oldest

          votes


















          1118














          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.






          share|improve this answer





















          • 4





            Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

            – ecdeveloper
            Dec 5 '14 at 11:29






          • 24





            Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

            – mklement0
            Dec 17 '14 at 21:03








          • 3





            @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

            – SSH This
            Feb 23 '16 at 22:36






          • 24





            @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

            – mklement0
            Feb 24 '16 at 0:02








          • 3





            console.dir(myObject, { depth: null }) is work for me

            – Veck Hsiao
            Apr 26 '17 at 5:08



















          515














          You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.



          console.log(JSON.stringify(myObject, null, 4));




          {
          "a": "a",
          "b": {
          "c": "c",
          "d": {
          "e": "e",
          "f": {
          "g": "g",
          "h": {
          "i": "i"
          }
          }
          }
          }
          }


          The third argument sets the indentation level, so you can adjust that as desired.



          More detail here if needed:



          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify






          share|improve this answer





















          • 2





            Ah this is handy too! thanks!

            – user1372449
            May 23 '12 at 23:47






          • 69





            +1 for not needing to require anything

            – Michael
            Feb 23 '13 at 1:22






          • 46





            Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

            – Ignacio Lago
            Jan 17 '14 at 16:47








          • 11





            keep in mind that this is not going to show undefined values

            – vxsx
            Feb 1 '15 at 12:37






          • 8





            this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

            – Larry W.
            Dec 23 '15 at 5:57





















          208















          A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer).



          tl;dr



          util.inspect() is at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly, so it's generally not necessary to require('util') and call util.inspect() directly.



          To get the desired output for the example in the question:



          console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion


          Details below.







          • console.log() (and its alias, console.info()):





            • If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:


              • o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'

              • Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:


                • Structural depth of the output is limited to 2 levels (the default).


                  • Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.



                • You can't turn syntax coloring on.






            • If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:


              • o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'

              • Note:


                • There is NO placeholder for representing objects util.inspect()-style.

                • JSON generated with %j is NOT pretty-printed.








          • console.dir():





            • Accepts only 1 argument to inspect, and always applies util.inspect() - essentially, a wrapper for util.inspect() without options by default; e.g.:


              • o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.




            • node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() - see below; e.g.:


              • console.dir({ one: 1, two: 'deux'}, { colors: true }); // node 0.11+: Prints object representation with syntax coloring.








          • The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;

            i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:


            • o = { one: 1, two: 'deux', foo: function(){} } // echoes the object definition with syntax coloring.




          util.inspect() automatically (and invariably) pretty-prints object and array representations, but produces multiline output only when needed - if everything fits on one line, only 1 line is printed.




          • By default, output is wrapped at around 60 characters thanks, Shrey
            , regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).


          • In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.



          If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:





          • Fails with objects that have circular references, such as module in the global context.


          • Methods (functions) will by design NOT be included.

          • You can't opt into showing hidden (non-enumerable) properties.

          • Example call:


            • JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces






          util.inspect() options object (2nd argument):



          source: http://nodejs.org/api/util.html#util_util_format_format



          An optional options object may be passed that alters certain aspects of the formatted string:





          • showHidden


            • if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.




          • depth


            • tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.




          • colors


            • if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [... - see link].




          • customInspect


            • if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.






          util.format() format-string placeholders (1st argument)



          source: http://nodejs.org/api/util.html#util_util_format_format





          • %s - String.


          • %d - Number (both integer and float).


          • %j - JSON.


          • % - single percent sign ('%'). This does not consume an argument.






          share|improve this answer





















          • 3





            @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

            – mklement0
            Apr 17 '18 at 15:30






          • 3





            @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

            – mklement0
            Apr 19 '18 at 23:30








          • 1





            Definitely the correct answer!

            – Michael Czechowski
            Oct 18 '18 at 8:33



















          48














          Another simple method is to convert it to json



          console.log('connection : %j', myObject);





          share|improve this answer



















          • 9





            Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

            – Dan Dascalescu
            Aug 1 '14 at 22:04











          • still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

            – SSH This
            Feb 23 '16 at 22:37






          • 1





            I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

            – jcollum
            Dec 12 '17 at 21:07











          • This is very handy and helpful if the object is small

            – Chinmay Samant
            Nov 9 '18 at 6:43



















          31














          Try this:



          console.dir(myObject,{depth:null})





          share|improve this answer





















          • 1





            That's the SHORTEST solution!

            – Martin Cup
            Jan 21 at 17:50



















          18














          You can also do



          console.log(JSON.stringify(myObject, null, 3));





          share|improve this answer

































            17














            perhaps console.dir is all you need.



            http://nodejs.org/api/console.html#console_console_dir_obj




            Uses util.inspect on obj and prints resulting string to stdout.




            use util option if you need more control.






            share|improve this answer



















            • 1





              console.dir is buggy and doesn't yet pass on the options object to util.inspect.

              – Dan Dascalescu
              Aug 1 '14 at 22:47











            • As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

              – mklement0
              Dec 17 '14 at 20:11





















            17














            Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:



            require("util").inspect.defaultOptions.depth = null;
            console.log(myObject);





            share|improve this answer































              13














              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.



              enter image description here



              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.






              share|improve this answer





















              • 1





                A message for me: try that out -> node.exe --inspect index.js

                – Lonely
                Mar 10 at 15:17



















              8














              Both of these usages can be applied



              // more compact and colour can be applied (better for process managers logging)

              console.dir(queryArgs, { depth: null, colors: true });

              // clear list of actual values

              console.log(JSON.stringify(queryArgs, undefined, 2));





              share|improve this answer

































                4














                You can simply add an inspect() method to your object which will override the representation of object in console.log messages



                eg:



                var myObject = {
                "a":"a",
                "b":{
                "c":"c",
                "d":{
                "e":"e",
                "f":{
                "g":"g",
                "h":{
                "i":"i"
                }
                }
                }
                }
                };
                myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }


                then, your object will be represented as required in both console.log and node shell






                share|improve this answer

































                  3














                  A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script



                  Ex.



                  DEBUG=* DEBUG_DEPTH=null node index.js



                  In you code



                  const debug = require('debug');
                  debug("%O", myObject);





                  share|improve this answer


























                  • Its giving error like "debug is not function"

                    – Bala
                    Nov 17 '17 at 2:23











                  • @Bala You will need to install "debug" module in your project "npm install debug --save"

                    – Chintan
                    Nov 18 '17 at 8:17





















                  2














                  The node REPL has a built-in solution for overriding how objects are displayed, see here.




                  The REPL module internally uses util.inspect(), when printing values.
                  However, util.inspect delegates the call to the object's inspect()
                  function, if it has one.







                  share|improve this answer
























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10729276%2fhow-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown
























                    13 Answers
                    13






                    active

                    oldest

                    votes








                    13 Answers
                    13






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    1118














                    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.






                    share|improve this answer





















                    • 4





                      Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                      – ecdeveloper
                      Dec 5 '14 at 11:29






                    • 24





                      Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                      – mklement0
                      Dec 17 '14 at 21:03








                    • 3





                      @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                      – SSH This
                      Feb 23 '16 at 22:36






                    • 24





                      @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                      – mklement0
                      Feb 24 '16 at 0:02








                    • 3





                      console.dir(myObject, { depth: null }) is work for me

                      – Veck Hsiao
                      Apr 26 '17 at 5:08
















                    1118














                    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.






                    share|improve this answer





















                    • 4





                      Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                      – ecdeveloper
                      Dec 5 '14 at 11:29






                    • 24





                      Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                      – mklement0
                      Dec 17 '14 at 21:03








                    • 3





                      @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                      – SSH This
                      Feb 23 '16 at 22:36






                    • 24





                      @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                      – mklement0
                      Feb 24 '16 at 0:02








                    • 3





                      console.dir(myObject, { depth: null }) is work for me

                      – Veck Hsiao
                      Apr 26 '17 at 5:08














                    1118












                    1118








                    1118







                    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.






                    share|improve this answer















                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Sep 4 '18 at 18:28









                    Ikbel

                    3,93421935




                    3,93421935










                    answered May 23 '12 at 23:30









                    250R250R

                    23.4k62925




                    23.4k62925








                    • 4





                      Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                      – ecdeveloper
                      Dec 5 '14 at 11:29






                    • 24





                      Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                      – mklement0
                      Dec 17 '14 at 21:03








                    • 3





                      @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                      – SSH This
                      Feb 23 '16 at 22:36






                    • 24





                      @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                      – mklement0
                      Feb 24 '16 at 0:02








                    • 3





                      console.dir(myObject, { depth: null }) is work for me

                      – Veck Hsiao
                      Apr 26 '17 at 5:08














                    • 4





                      Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                      – ecdeveloper
                      Dec 5 '14 at 11:29






                    • 24





                      Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                      – mklement0
                      Dec 17 '14 at 21:03








                    • 3





                      @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                      – SSH This
                      Feb 23 '16 at 22:36






                    • 24





                      @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                      – mklement0
                      Feb 24 '16 at 0:02








                    • 3





                      console.dir(myObject, { depth: null }) is work for me

                      – Veck Hsiao
                      Apr 26 '17 at 5:08








                    4




                    4





                    Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                    – ecdeveloper
                    Dec 5 '14 at 11:29





                    Nice solution. Though no need to specify {showHidden: false} as long as it defaults to false.

                    – ecdeveloper
                    Dec 5 '14 at 11:29




                    24




                    24





                    Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                    – mklement0
                    Dec 17 '14 at 21:03







                    Good to know; not sure when it was introduced, but as of at least node v0.10.33 console.log() implicitly applies util.inspect() to its arguments, assuming the 1st one is not a format string. If you're happy with util.inspect()'s default options, simply console.log(myObject) will do - no need to require util; console.dir() does the same, but accepts only ` object to inspect; as of at least v0.11.14, you can pass the options object for util.inspect() as the 2nd argument; my answer has more details.

                    – mklement0
                    Dec 17 '14 at 21:03






                    3




                    3





                    @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                    – SSH This
                    Feb 23 '16 at 22:36





                    @mklement0 I have node v5.3.0 and when I console.log(obj) it still prints [Object] for deeply nested objects :( I really wish it would behave as you describe.

                    – SSH This
                    Feb 23 '16 at 22:36




                    24




                    24





                    @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                    – mklement0
                    Feb 24 '16 at 0:02







                    @SSH: console.log() is invariably limited to 2 levels (because it uses util.inspect()'s default without allowing you to change it); console.dir() has the same limit by default, but you can pass in an options object as the 2nd argument to change that (which is passed through to util.inspect(); note that console.dir() can only ever print 1 object at a time, however. To print with unlimited depth, use console.dir(myObject, { depth: null }).

                    – mklement0
                    Feb 24 '16 at 0:02






                    3




                    3





                    console.dir(myObject, { depth: null }) is work for me

                    – Veck Hsiao
                    Apr 26 '17 at 5:08





                    console.dir(myObject, { depth: null }) is work for me

                    – Veck Hsiao
                    Apr 26 '17 at 5:08













                    515














                    You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.



                    console.log(JSON.stringify(myObject, null, 4));




                    {
                    "a": "a",
                    "b": {
                    "c": "c",
                    "d": {
                    "e": "e",
                    "f": {
                    "g": "g",
                    "h": {
                    "i": "i"
                    }
                    }
                    }
                    }
                    }


                    The third argument sets the indentation level, so you can adjust that as desired.



                    More detail here if needed:



                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify






                    share|improve this answer





















                    • 2





                      Ah this is handy too! thanks!

                      – user1372449
                      May 23 '12 at 23:47






                    • 69





                      +1 for not needing to require anything

                      – Michael
                      Feb 23 '13 at 1:22






                    • 46





                      Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                      – Ignacio Lago
                      Jan 17 '14 at 16:47








                    • 11





                      keep in mind that this is not going to show undefined values

                      – vxsx
                      Feb 1 '15 at 12:37






                    • 8





                      this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                      – Larry W.
                      Dec 23 '15 at 5:57


















                    515














                    You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.



                    console.log(JSON.stringify(myObject, null, 4));




                    {
                    "a": "a",
                    "b": {
                    "c": "c",
                    "d": {
                    "e": "e",
                    "f": {
                    "g": "g",
                    "h": {
                    "i": "i"
                    }
                    }
                    }
                    }
                    }


                    The third argument sets the indentation level, so you can adjust that as desired.



                    More detail here if needed:



                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify






                    share|improve this answer





















                    • 2





                      Ah this is handy too! thanks!

                      – user1372449
                      May 23 '12 at 23:47






                    • 69





                      +1 for not needing to require anything

                      – Michael
                      Feb 23 '13 at 1:22






                    • 46





                      Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                      – Ignacio Lago
                      Jan 17 '14 at 16:47








                    • 11





                      keep in mind that this is not going to show undefined values

                      – vxsx
                      Feb 1 '15 at 12:37






                    • 8





                      this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                      – Larry W.
                      Dec 23 '15 at 5:57
















                    515












                    515








                    515







                    You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.



                    console.log(JSON.stringify(myObject, null, 4));




                    {
                    "a": "a",
                    "b": {
                    "c": "c",
                    "d": {
                    "e": "e",
                    "f": {
                    "g": "g",
                    "h": {
                    "i": "i"
                    }
                    }
                    }
                    }
                    }


                    The third argument sets the indentation level, so you can adjust that as desired.



                    More detail here if needed:



                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify






                    share|improve this answer















                    You can use JSON.stringify, and get some nice indentation as well as perhaps easier to remember syntax.



                    console.log(JSON.stringify(myObject, null, 4));




                    {
                    "a": "a",
                    "b": {
                    "c": "c",
                    "d": {
                    "e": "e",
                    "f": {
                    "g": "g",
                    "h": {
                    "i": "i"
                    }
                    }
                    }
                    }
                    }


                    The third argument sets the indentation level, so you can adjust that as desired.



                    More detail here if needed:



                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Jul 7 '13 at 6:28


























                    community wiki





                    2 revs, 2 users 92%
                    user1106925









                    • 2





                      Ah this is handy too! thanks!

                      – user1372449
                      May 23 '12 at 23:47






                    • 69





                      +1 for not needing to require anything

                      – Michael
                      Feb 23 '13 at 1:22






                    • 46





                      Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                      – Ignacio Lago
                      Jan 17 '14 at 16:47








                    • 11





                      keep in mind that this is not going to show undefined values

                      – vxsx
                      Feb 1 '15 at 12:37






                    • 8





                      this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                      – Larry W.
                      Dec 23 '15 at 5:57
















                    • 2





                      Ah this is handy too! thanks!

                      – user1372449
                      May 23 '12 at 23:47






                    • 69





                      +1 for not needing to require anything

                      – Michael
                      Feb 23 '13 at 1:22






                    • 46





                      Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                      – Ignacio Lago
                      Jan 17 '14 at 16:47








                    • 11





                      keep in mind that this is not going to show undefined values

                      – vxsx
                      Feb 1 '15 at 12:37






                    • 8





                      this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                      – Larry W.
                      Dec 23 '15 at 5:57










                    2




                    2





                    Ah this is handy too! thanks!

                    – user1372449
                    May 23 '12 at 23:47





                    Ah this is handy too! thanks!

                    – user1372449
                    May 23 '12 at 23:47




                    69




                    69





                    +1 for not needing to require anything

                    – Michael
                    Feb 23 '13 at 1:22





                    +1 for not needing to require anything

                    – Michael
                    Feb 23 '13 at 1:22




                    46




                    46





                    Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                    – Ignacio Lago
                    Jan 17 '14 at 16:47







                    Note that you cannot JSON.stringify objects with circular references. Like it would occur with DOM objects, for example. Stringify will throw an "Error: Converting circular structure to JSON".

                    – Ignacio Lago
                    Jan 17 '14 at 16:47






                    11




                    11





                    keep in mind that this is not going to show undefined values

                    – vxsx
                    Feb 1 '15 at 12:37





                    keep in mind that this is not going to show undefined values

                    – vxsx
                    Feb 1 '15 at 12:37




                    8




                    8





                    this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                    – Larry W.
                    Dec 23 '15 at 5:57







                    this isn't the full object. objects containing only functions will be {}. Of course that may be a positive or a negative depending on what you want to print out.

                    – Larry W.
                    Dec 23 '15 at 5:57













                    208















                    A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer).



                    tl;dr



                    util.inspect() is at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly, so it's generally not necessary to require('util') and call util.inspect() directly.



                    To get the desired output for the example in the question:



                    console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion


                    Details below.







                    • console.log() (and its alias, console.info()):





                      • If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'

                        • Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:


                          • Structural depth of the output is limited to 2 levels (the default).


                            • Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.



                          • You can't turn syntax coloring on.






                      • If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'

                        • Note:


                          • There is NO placeholder for representing objects util.inspect()-style.

                          • JSON generated with %j is NOT pretty-printed.








                    • console.dir():





                      • Accepts only 1 argument to inspect, and always applies util.inspect() - essentially, a wrapper for util.inspect() without options by default; e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.




                      • node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() - see below; e.g.:


                        • console.dir({ one: 1, two: 'deux'}, { colors: true }); // node 0.11+: Prints object representation with syntax coloring.








                    • The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;

                      i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:


                      • o = { one: 1, two: 'deux', foo: function(){} } // echoes the object definition with syntax coloring.




                    util.inspect() automatically (and invariably) pretty-prints object and array representations, but produces multiline output only when needed - if everything fits on one line, only 1 line is printed.




                    • By default, output is wrapped at around 60 characters thanks, Shrey
                      , regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).


                    • In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.



                    If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:





                    • Fails with objects that have circular references, such as module in the global context.


                    • Methods (functions) will by design NOT be included.

                    • You can't opt into showing hidden (non-enumerable) properties.

                    • Example call:


                      • JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces






                    util.inspect() options object (2nd argument):



                    source: http://nodejs.org/api/util.html#util_util_format_format



                    An optional options object may be passed that alters certain aspects of the formatted string:





                    • showHidden


                      • if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.




                    • depth


                      • tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.




                    • colors


                      • if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [... - see link].




                    • customInspect


                      • if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.






                    util.format() format-string placeholders (1st argument)



                    source: http://nodejs.org/api/util.html#util_util_format_format





                    • %s - String.


                    • %d - Number (both integer and float).


                    • %j - JSON.


                    • % - single percent sign ('%'). This does not consume an argument.






                    share|improve this answer





















                    • 3





                      @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                      – mklement0
                      Apr 17 '18 at 15:30






                    • 3





                      @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                      – mklement0
                      Apr 19 '18 at 23:30








                    • 1





                      Definitely the correct answer!

                      – Michael Czechowski
                      Oct 18 '18 at 8:33
















                    208















                    A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer).



                    tl;dr



                    util.inspect() is at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly, so it's generally not necessary to require('util') and call util.inspect() directly.



                    To get the desired output for the example in the question:



                    console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion


                    Details below.







                    • console.log() (and its alias, console.info()):





                      • If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'

                        • Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:


                          • Structural depth of the output is limited to 2 levels (the default).


                            • Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.



                          • You can't turn syntax coloring on.






                      • If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'

                        • Note:


                          • There is NO placeholder for representing objects util.inspect()-style.

                          • JSON generated with %j is NOT pretty-printed.








                    • console.dir():





                      • Accepts only 1 argument to inspect, and always applies util.inspect() - essentially, a wrapper for util.inspect() without options by default; e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.




                      • node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() - see below; e.g.:


                        • console.dir({ one: 1, two: 'deux'}, { colors: true }); // node 0.11+: Prints object representation with syntax coloring.








                    • The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;

                      i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:


                      • o = { one: 1, two: 'deux', foo: function(){} } // echoes the object definition with syntax coloring.




                    util.inspect() automatically (and invariably) pretty-prints object and array representations, but produces multiline output only when needed - if everything fits on one line, only 1 line is printed.




                    • By default, output is wrapped at around 60 characters thanks, Shrey
                      , regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).


                    • In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.



                    If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:





                    • Fails with objects that have circular references, such as module in the global context.


                    • Methods (functions) will by design NOT be included.

                    • You can't opt into showing hidden (non-enumerable) properties.

                    • Example call:


                      • JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces






                    util.inspect() options object (2nd argument):



                    source: http://nodejs.org/api/util.html#util_util_format_format



                    An optional options object may be passed that alters certain aspects of the formatted string:





                    • showHidden


                      • if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.




                    • depth


                      • tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.




                    • colors


                      • if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [... - see link].




                    • customInspect


                      • if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.






                    util.format() format-string placeholders (1st argument)



                    source: http://nodejs.org/api/util.html#util_util_format_format





                    • %s - String.


                    • %d - Number (both integer and float).


                    • %j - JSON.


                    • % - single percent sign ('%'). This does not consume an argument.






                    share|improve this answer





















                    • 3





                      @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                      – mklement0
                      Apr 17 '18 at 15:30






                    • 3





                      @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                      – mklement0
                      Apr 19 '18 at 23:30








                    • 1





                      Definitely the correct answer!

                      – Michael Czechowski
                      Oct 18 '18 at 8:33














                    208












                    208








                    208








                    A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer).



                    tl;dr



                    util.inspect() is at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly, so it's generally not necessary to require('util') and call util.inspect() directly.



                    To get the desired output for the example in the question:



                    console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion


                    Details below.







                    • console.log() (and its alias, console.info()):





                      • If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'

                        • Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:


                          • Structural depth of the output is limited to 2 levels (the default).


                            • Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.



                          • You can't turn syntax coloring on.






                      • If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'

                        • Note:


                          • There is NO placeholder for representing objects util.inspect()-style.

                          • JSON generated with %j is NOT pretty-printed.








                    • console.dir():





                      • Accepts only 1 argument to inspect, and always applies util.inspect() - essentially, a wrapper for util.inspect() without options by default; e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.




                      • node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() - see below; e.g.:


                        • console.dir({ one: 1, two: 'deux'}, { colors: true }); // node 0.11+: Prints object representation with syntax coloring.








                    • The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;

                      i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:


                      • o = { one: 1, two: 'deux', foo: function(){} } // echoes the object definition with syntax coloring.




                    util.inspect() automatically (and invariably) pretty-prints object and array representations, but produces multiline output only when needed - if everything fits on one line, only 1 line is printed.




                    • By default, output is wrapped at around 60 characters thanks, Shrey
                      , regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).


                    • In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.



                    If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:





                    • Fails with objects that have circular references, such as module in the global context.


                    • Methods (functions) will by design NOT be included.

                    • You can't opt into showing hidden (non-enumerable) properties.

                    • Example call:


                      • JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces






                    util.inspect() options object (2nd argument):



                    source: http://nodejs.org/api/util.html#util_util_format_format



                    An optional options object may be passed that alters certain aspects of the formatted string:





                    • showHidden


                      • if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.




                    • depth


                      • tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.




                    • colors


                      • if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [... - see link].




                    • customInspect


                      • if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.






                    util.format() format-string placeholders (1st argument)



                    source: http://nodejs.org/api/util.html#util_util_format_format





                    • %s - String.


                    • %d - Number (both integer and float).


                    • %j - JSON.


                    • % - single percent sign ('%'). This does not consume an argument.






                    share|improve this answer
















                    A compilation of the many useful answers from (at least) Node.js v0.10.33 (stable) / v0.11.14 (unstable) presumably through (at least) v7.7.4 (the version current as of the latest update to this answer).



                    tl;dr



                    util.inspect() is at the heart of diagnostic output: console.log() and console.dir() as well as the Node.js REPL use util.inspect() implicitly, so it's generally not necessary to require('util') and call util.inspect() directly.



                    To get the desired output for the example in the question:



                    console.dir(myObject, { depth: null }); // `depth: null` ensures unlimited recursion


                    Details below.







                    • console.log() (and its alias, console.info()):





                      • If the 1st argument is NOT a format string: util.inspect() is automatically applied to every argument:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log(o, [1,2,3]) // -> '{ one: 1, two: 'deux', foo: [Function] } [ 1, 2, 3 ]'

                        • Note that you cannot pass options through util.inspect() in this case, which implies 2 notable limitations:


                          • Structural depth of the output is limited to 2 levels (the default).


                            • Since you cannot change this with console.log(), you must instead use console.dir(): console.dir(myObject, { depth: null } prints with unlimited depth; see below.



                          • You can't turn syntax coloring on.






                      • If the 1st argument IS a format string (see below): uses util.format() to print the remaining arguments based on the format string (see below); e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.log('o as JSON: %j', o) // -> 'o as JSON: {"one":1,"two":"deux"}'

                        • Note:


                          • There is NO placeholder for representing objects util.inspect()-style.

                          • JSON generated with %j is NOT pretty-printed.








                    • console.dir():





                      • Accepts only 1 argument to inspect, and always applies util.inspect() - essentially, a wrapper for util.inspect() without options by default; e.g.:


                        • o = { one: 1, two: 'deux', foo: function(){} }; console.dir(o); // Effectively the same as console.log(o) in this case.




                      • node.js v0.11.14+: The optional 2nd argument specifies options for util.inspect() - see below; e.g.:


                        • console.dir({ one: 1, two: 'deux'}, { colors: true }); // node 0.11+: Prints object representation with syntax coloring.








                    • The REPL: implicitly prints any expression's return value with util.inspect() with syntax coloring;

                      i.e., just typing a variable's name and hitting Enter will print an inspected version of its value; e.g.:


                      • o = { one: 1, two: 'deux', foo: function(){} } // echoes the object definition with syntax coloring.




                    util.inspect() automatically (and invariably) pretty-prints object and array representations, but produces multiline output only when needed - if everything fits on one line, only 1 line is printed.




                    • By default, output is wrapped at around 60 characters thanks, Shrey
                      , regardless of whether the output is sent to a file or a terminal. In practice, since line breaks only happen at property boundaries, you will often end up with shorter lines, but they can also be longer (e.g., with long property values).


                    • In v6.3.0+ you can use the breakLength option to override the 60-character limit; if you set it to Infinity, everything is output on a single line.



                    If you want more control over pretty-printing, consider using JSON.stringify() with a 3rd argument, but note the following:





                    • Fails with objects that have circular references, such as module in the global context.


                    • Methods (functions) will by design NOT be included.

                    • You can't opt into showing hidden (non-enumerable) properties.

                    • Example call:


                      • JSON.stringify({ one: 1, two: 'deux', three: true}, undefined, 2); // creates a pretty-printed multiline JSON representation indented with 2 spaces






                    util.inspect() options object (2nd argument):



                    source: http://nodejs.org/api/util.html#util_util_format_format



                    An optional options object may be passed that alters certain aspects of the formatted string:





                    • showHidden


                      • if true, then the object's non-enumerable properties [those designated not to show up when you use for keys in obj or Object.keys(obj)] will be shown too. Defaults to false.




                    • depth


                      • tells inspect how many times to recurse while formatting the object. This is useful for inspecting large complicated objects. Defaults to 2. To make it recurse indefinitely, pass null.




                    • colors


                      • if true, then the output will be styled with ANSI color codes. Defaults to false. Colors are customizable [... - see link].




                    • customInspect


                      • if false, then custom inspect() functions defined on the objects being inspected won't be called. Defaults to true.






                    util.format() format-string placeholders (1st argument)



                    source: http://nodejs.org/api/util.html#util_util_format_format





                    • %s - String.


                    • %d - Number (both integer and float).


                    • %j - JSON.


                    • % - single percent sign ('%'). This does not consume an argument.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 8 '18 at 22:46

























                    answered Dec 17 '14 at 20:57









                    mklement0mklement0

                    137k22255293




                    137k22255293








                    • 3





                      @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                      – mklement0
                      Apr 17 '18 at 15:30






                    • 3





                      @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                      – mklement0
                      Apr 19 '18 at 23:30








                    • 1





                      Definitely the correct answer!

                      – Michael Czechowski
                      Oct 18 '18 at 8:33














                    • 3





                      @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                      – mklement0
                      Apr 17 '18 at 15:30






                    • 3





                      @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                      – mklement0
                      Apr 19 '18 at 23:30








                    • 1





                      Definitely the correct answer!

                      – Michael Czechowski
                      Oct 18 '18 at 8:33








                    3




                    3





                    @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                    – mklement0
                    Apr 17 '18 at 15:30





                    @YvesM. I'm glad you found something useful in it. The "messiness" stems from packing a lot of information into a concise answer, and bold-facing key parts is meant to make locating the important parts easier. How would you make it less messy without sacrificing these goals?

                    – mklement0
                    Apr 17 '18 at 15:30




                    3




                    3





                    @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                    – mklement0
                    Apr 19 '18 at 23:30







                    @Ruudjah: bold-facing key parts is not "randomly making things bold" (although what the key parts are is a matter of taste, to a degree). Formatting code elements as such to my mind helps readability.

                    – mklement0
                    Apr 19 '18 at 23:30






                    1




                    1





                    Definitely the correct answer!

                    – Michael Czechowski
                    Oct 18 '18 at 8:33





                    Definitely the correct answer!

                    – Michael Czechowski
                    Oct 18 '18 at 8:33











                    48














                    Another simple method is to convert it to json



                    console.log('connection : %j', myObject);





                    share|improve this answer



















                    • 9





                      Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                      – Dan Dascalescu
                      Aug 1 '14 at 22:04











                    • still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                      – SSH This
                      Feb 23 '16 at 22:37






                    • 1





                      I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                      – jcollum
                      Dec 12 '17 at 21:07











                    • This is very handy and helpful if the object is small

                      – Chinmay Samant
                      Nov 9 '18 at 6:43
















                    48














                    Another simple method is to convert it to json



                    console.log('connection : %j', myObject);





                    share|improve this answer



















                    • 9





                      Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                      – Dan Dascalescu
                      Aug 1 '14 at 22:04











                    • still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                      – SSH This
                      Feb 23 '16 at 22:37






                    • 1





                      I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                      – jcollum
                      Dec 12 '17 at 21:07











                    • This is very handy and helpful if the object is small

                      – Chinmay Samant
                      Nov 9 '18 at 6:43














                    48












                    48








                    48







                    Another simple method is to convert it to json



                    console.log('connection : %j', myObject);





                    share|improve this answer













                    Another simple method is to convert it to json



                    console.log('connection : %j', myObject);






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 15 '14 at 16:05









                    niksmacniksmac

                    1,29431740




                    1,29431740








                    • 9





                      Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                      – Dan Dascalescu
                      Aug 1 '14 at 22:04











                    • still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                      – SSH This
                      Feb 23 '16 at 22:37






                    • 1





                      I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                      – jcollum
                      Dec 12 '17 at 21:07











                    • This is very handy and helpful if the object is small

                      – Chinmay Samant
                      Nov 9 '18 at 6:43














                    • 9





                      Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                      – Dan Dascalescu
                      Aug 1 '14 at 22:04











                    • still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                      – SSH This
                      Feb 23 '16 at 22:37






                    • 1





                      I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                      – jcollum
                      Dec 12 '17 at 21:07











                    • This is very handy and helpful if the object is small

                      – Chinmay Samant
                      Nov 9 '18 at 6:43








                    9




                    9





                    Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                    – Dan Dascalescu
                    Aug 1 '14 at 22:04





                    Nice trick but the output won't be prettified, which makes it hard to read for large objects (the point of the question).

                    – Dan Dascalescu
                    Aug 1 '14 at 22:04













                    still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                    – SSH This
                    Feb 23 '16 at 22:37





                    still very useful, and quicker to copy and paste into jsonlint.com than requiring utils :)

                    – SSH This
                    Feb 23 '16 at 22:37




                    1




                    1





                    I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                    – jcollum
                    Dec 12 '17 at 21:07





                    I think this one is great when you have an editor that will format json for you but you just need to copy it out from REPL

                    – jcollum
                    Dec 12 '17 at 21:07













                    This is very handy and helpful if the object is small

                    – Chinmay Samant
                    Nov 9 '18 at 6:43





                    This is very handy and helpful if the object is small

                    – Chinmay Samant
                    Nov 9 '18 at 6:43











                    31














                    Try this:



                    console.dir(myObject,{depth:null})





                    share|improve this answer





















                    • 1





                      That's the SHORTEST solution!

                      – Martin Cup
                      Jan 21 at 17:50
















                    31














                    Try this:



                    console.dir(myObject,{depth:null})





                    share|improve this answer





















                    • 1





                      That's the SHORTEST solution!

                      – Martin Cup
                      Jan 21 at 17:50














                    31












                    31








                    31







                    Try this:



                    console.dir(myObject,{depth:null})





                    share|improve this answer















                    Try this:



                    console.dir(myObject,{depth:null})






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 19 '15 at 12:12









                    MarmiK

                    4,56342841




                    4,56342841










                    answered Oct 19 '15 at 11:05









                    hirrahirra

                    535513




                    535513








                    • 1





                      That's the SHORTEST solution!

                      – Martin Cup
                      Jan 21 at 17:50














                    • 1





                      That's the SHORTEST solution!

                      – Martin Cup
                      Jan 21 at 17:50








                    1




                    1





                    That's the SHORTEST solution!

                    – Martin Cup
                    Jan 21 at 17:50





                    That's the SHORTEST solution!

                    – Martin Cup
                    Jan 21 at 17:50











                    18














                    You can also do



                    console.log(JSON.stringify(myObject, null, 3));





                    share|improve this answer






























                      18














                      You can also do



                      console.log(JSON.stringify(myObject, null, 3));





                      share|improve this answer




























                        18












                        18








                        18







                        You can also do



                        console.log(JSON.stringify(myObject, null, 3));





                        share|improve this answer















                        You can also do



                        console.log(JSON.stringify(myObject, null, 3));






                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 9 '16 at 2:27









                        evandrix

                        4,81332330




                        4,81332330










                        answered Feb 14 '16 at 10:32









                        EesaEesa

                        1,00521737




                        1,00521737























                            17














                            perhaps console.dir is all you need.



                            http://nodejs.org/api/console.html#console_console_dir_obj




                            Uses util.inspect on obj and prints resulting string to stdout.




                            use util option if you need more control.






                            share|improve this answer



















                            • 1





                              console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                              – Dan Dascalescu
                              Aug 1 '14 at 22:47











                            • As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                              – mklement0
                              Dec 17 '14 at 20:11


















                            17














                            perhaps console.dir is all you need.



                            http://nodejs.org/api/console.html#console_console_dir_obj




                            Uses util.inspect on obj and prints resulting string to stdout.




                            use util option if you need more control.






                            share|improve this answer



















                            • 1





                              console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                              – Dan Dascalescu
                              Aug 1 '14 at 22:47











                            • As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                              – mklement0
                              Dec 17 '14 at 20:11
















                            17












                            17








                            17







                            perhaps console.dir is all you need.



                            http://nodejs.org/api/console.html#console_console_dir_obj




                            Uses util.inspect on obj and prints resulting string to stdout.




                            use util option if you need more control.






                            share|improve this answer













                            perhaps console.dir is all you need.



                            http://nodejs.org/api/console.html#console_console_dir_obj




                            Uses util.inspect on obj and prints resulting string to stdout.




                            use util option if you need more control.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 2 '14 at 1:27









                            Luke WLuke W

                            4,03222625




                            4,03222625








                            • 1





                              console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                              – Dan Dascalescu
                              Aug 1 '14 at 22:47











                            • As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                              – mklement0
                              Dec 17 '14 at 20:11
















                            • 1





                              console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                              – Dan Dascalescu
                              Aug 1 '14 at 22:47











                            • As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                              – mklement0
                              Dec 17 '14 at 20:11










                            1




                            1





                            console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                            – Dan Dascalescu
                            Aug 1 '14 at 22:47





                            console.dir is buggy and doesn't yet pass on the options object to util.inspect.

                            – Dan Dascalescu
                            Aug 1 '14 at 22:47













                            As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                            – mklement0
                            Dec 17 '14 at 20:11







                            As of (at least) v0.11.14, you can pass an options object as the 2nd argument, which is passed to util.inspect().

                            – mklement0
                            Dec 17 '14 at 20:11













                            17














                            Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:



                            require("util").inspect.defaultOptions.depth = null;
                            console.log(myObject);





                            share|improve this answer




























                              17














                              Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:



                              require("util").inspect.defaultOptions.depth = null;
                              console.log(myObject);





                              share|improve this answer


























                                17












                                17








                                17







                                Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:



                                require("util").inspect.defaultOptions.depth = null;
                                console.log(myObject);





                                share|improve this answer













                                Since Node.js 6.4.0, this can be elegantly solved with util.inspect.defaultOptions:



                                require("util").inspect.defaultOptions.depth = null;
                                console.log(myObject);






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jan 26 '17 at 20:32









                                silverwindsilverwind

                                1,072917




                                1,072917























                                    13














                                    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.



                                    enter image description here



                                    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.






                                    share|improve this answer





















                                    • 1





                                      A message for me: try that out -> node.exe --inspect index.js

                                      – Lonely
                                      Mar 10 at 15:17
















                                    13














                                    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.



                                    enter image description here



                                    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.






                                    share|improve this answer





















                                    • 1





                                      A message for me: try that out -> node.exe --inspect index.js

                                      – Lonely
                                      Mar 10 at 15:17














                                    13












                                    13








                                    13







                                    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.



                                    enter image description here



                                    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.






                                    share|improve this answer















                                    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.



                                    enter image description here



                                    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.







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Apr 17 '17 at 11:43

























                                    answered Apr 17 '17 at 11:37









                                    AliAli

                                    12.1k106583




                                    12.1k106583








                                    • 1





                                      A message for me: try that out -> node.exe --inspect index.js

                                      – Lonely
                                      Mar 10 at 15:17














                                    • 1





                                      A message for me: try that out -> node.exe --inspect index.js

                                      – Lonely
                                      Mar 10 at 15:17








                                    1




                                    1





                                    A message for me: try that out -> node.exe --inspect index.js

                                    – Lonely
                                    Mar 10 at 15:17





                                    A message for me: try that out -> node.exe --inspect index.js

                                    – Lonely
                                    Mar 10 at 15:17











                                    8














                                    Both of these usages can be applied



                                    // more compact and colour can be applied (better for process managers logging)

                                    console.dir(queryArgs, { depth: null, colors: true });

                                    // clear list of actual values

                                    console.log(JSON.stringify(queryArgs, undefined, 2));





                                    share|improve this answer






























                                      8














                                      Both of these usages can be applied



                                      // more compact and colour can be applied (better for process managers logging)

                                      console.dir(queryArgs, { depth: null, colors: true });

                                      // clear list of actual values

                                      console.log(JSON.stringify(queryArgs, undefined, 2));





                                      share|improve this answer




























                                        8












                                        8








                                        8







                                        Both of these usages can be applied



                                        // more compact and colour can be applied (better for process managers logging)

                                        console.dir(queryArgs, { depth: null, colors: true });

                                        // clear list of actual values

                                        console.log(JSON.stringify(queryArgs, undefined, 2));





                                        share|improve this answer















                                        Both of these usages can be applied



                                        // more compact and colour can be applied (better for process managers logging)

                                        console.dir(queryArgs, { depth: null, colors: true });

                                        // clear list of actual values

                                        console.log(JSON.stringify(queryArgs, undefined, 2));






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Jan 11 '18 at 13:16









                                        Dmitriy

                                        4,996112034




                                        4,996112034










                                        answered Jan 11 '18 at 12:55









                                        ErceErce

                                        10618




                                        10618























                                            4














                                            You can simply add an inspect() method to your object which will override the representation of object in console.log messages



                                            eg:



                                            var myObject = {
                                            "a":"a",
                                            "b":{
                                            "c":"c",
                                            "d":{
                                            "e":"e",
                                            "f":{
                                            "g":"g",
                                            "h":{
                                            "i":"i"
                                            }
                                            }
                                            }
                                            }
                                            };
                                            myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }


                                            then, your object will be represented as required in both console.log and node shell






                                            share|improve this answer






























                                              4














                                              You can simply add an inspect() method to your object which will override the representation of object in console.log messages



                                              eg:



                                              var myObject = {
                                              "a":"a",
                                              "b":{
                                              "c":"c",
                                              "d":{
                                              "e":"e",
                                              "f":{
                                              "g":"g",
                                              "h":{
                                              "i":"i"
                                              }
                                              }
                                              }
                                              }
                                              };
                                              myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }


                                              then, your object will be represented as required in both console.log and node shell






                                              share|improve this answer




























                                                4












                                                4








                                                4







                                                You can simply add an inspect() method to your object which will override the representation of object in console.log messages



                                                eg:



                                                var myObject = {
                                                "a":"a",
                                                "b":{
                                                "c":"c",
                                                "d":{
                                                "e":"e",
                                                "f":{
                                                "g":"g",
                                                "h":{
                                                "i":"i"
                                                }
                                                }
                                                }
                                                }
                                                };
                                                myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }


                                                then, your object will be represented as required in both console.log and node shell






                                                share|improve this answer















                                                You can simply add an inspect() method to your object which will override the representation of object in console.log messages



                                                eg:



                                                var myObject = {
                                                "a":"a",
                                                "b":{
                                                "c":"c",
                                                "d":{
                                                "e":"e",
                                                "f":{
                                                "g":"g",
                                                "h":{
                                                "i":"i"
                                                }
                                                }
                                                }
                                                }
                                                };
                                                myObject.inspect = function(){ return JSON.stringify( this, null, ' ' ); }


                                                then, your object will be represented as required in both console.log and node shell







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Nov 25 '15 at 6:27









                                                T J

                                                32.9k957112




                                                32.9k957112










                                                answered Sep 30 '15 at 12:47









                                                harish2704harish2704

                                                338310




                                                338310























                                                    3














                                                    A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script



                                                    Ex.



                                                    DEBUG=* DEBUG_DEPTH=null node index.js



                                                    In you code



                                                    const debug = require('debug');
                                                    debug("%O", myObject);





                                                    share|improve this answer


























                                                    • Its giving error like "debug is not function"

                                                      – Bala
                                                      Nov 17 '17 at 2:23











                                                    • @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                      – Chintan
                                                      Nov 18 '17 at 8:17


















                                                    3














                                                    A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script



                                                    Ex.



                                                    DEBUG=* DEBUG_DEPTH=null node index.js



                                                    In you code



                                                    const debug = require('debug');
                                                    debug("%O", myObject);





                                                    share|improve this answer


























                                                    • Its giving error like "debug is not function"

                                                      – Bala
                                                      Nov 17 '17 at 2:23











                                                    • @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                      – Chintan
                                                      Nov 18 '17 at 8:17
















                                                    3












                                                    3








                                                    3







                                                    A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script



                                                    Ex.



                                                    DEBUG=* DEBUG_DEPTH=null node index.js



                                                    In you code



                                                    const debug = require('debug');
                                                    debug("%O", myObject);





                                                    share|improve this answer















                                                    A simple trick would be use debug module to add DEBUG_DEPTH=null as environment variable when running the script



                                                    Ex.



                                                    DEBUG=* DEBUG_DEPTH=null node index.js



                                                    In you code



                                                    const debug = require('debug');
                                                    debug("%O", myObject);






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 18 '17 at 8:18

























                                                    answered Jul 27 '17 at 11:35









                                                    ChintanChintan

                                                    433414




                                                    433414













                                                    • Its giving error like "debug is not function"

                                                      – Bala
                                                      Nov 17 '17 at 2:23











                                                    • @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                      – Chintan
                                                      Nov 18 '17 at 8:17





















                                                    • Its giving error like "debug is not function"

                                                      – Bala
                                                      Nov 17 '17 at 2:23











                                                    • @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                      – Chintan
                                                      Nov 18 '17 at 8:17



















                                                    Its giving error like "debug is not function"

                                                    – Bala
                                                    Nov 17 '17 at 2:23





                                                    Its giving error like "debug is not function"

                                                    – Bala
                                                    Nov 17 '17 at 2:23













                                                    @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                    – Chintan
                                                    Nov 18 '17 at 8:17







                                                    @Bala You will need to install "debug" module in your project "npm install debug --save"

                                                    – Chintan
                                                    Nov 18 '17 at 8:17













                                                    2














                                                    The node REPL has a built-in solution for overriding how objects are displayed, see here.




                                                    The REPL module internally uses util.inspect(), when printing values.
                                                    However, util.inspect delegates the call to the object's inspect()
                                                    function, if it has one.







                                                    share|improve this answer




























                                                      2














                                                      The node REPL has a built-in solution for overriding how objects are displayed, see here.




                                                      The REPL module internally uses util.inspect(), when printing values.
                                                      However, util.inspect delegates the call to the object's inspect()
                                                      function, if it has one.







                                                      share|improve this answer


























                                                        2












                                                        2








                                                        2







                                                        The node REPL has a built-in solution for overriding how objects are displayed, see here.




                                                        The REPL module internally uses util.inspect(), when printing values.
                                                        However, util.inspect delegates the call to the object's inspect()
                                                        function, if it has one.







                                                        share|improve this answer













                                                        The node REPL has a built-in solution for overriding how objects are displayed, see here.




                                                        The REPL module internally uses util.inspect(), when printing values.
                                                        However, util.inspect delegates the call to the object's inspect()
                                                        function, if it has one.








                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Feb 11 '16 at 17:02









                                                        LloydLloyd

                                                        6,2872646




                                                        6,2872646






























                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10729276%2fhow-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                                                            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                                                            A Topological Invariant for $pi_3(U(n))$