{"id":8364,"date":"2023-07-27T09:51:01","date_gmt":"2023-07-27T09:51:01","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=8364"},"modified":"2023-08-07T04:28:46","modified_gmt":"2023-08-07T04:28:46","slug":"print-in-nodejs","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/node\/print-in-nodejs","title":{"rendered":"How to Print Object in Node JS"},"content":{"rendered":"<p>Basic console.log will not go through long and complex objects, and may decide to just print [Object] instead.<br \/>\nTwo of the suitable ways to print the object with nested properties are exemplified below:<\/p>\n<p>1.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">util.inspect(object[, options])\r\nconst util = require('util'),\r\nconst obj = {} \/\/ some complex object\r\n\r\nconsole.log(util.inspect(obj, {depth: null}));\r\n\r\n\/\/{ depth: null } instructs util.inspect to open everything until it gets to a circular reference\r\n\r\n\/\/There are other options also available, such as showHidden, colors, maxStringLength, maxArrayLength, sorted, etc.\r\n\r\n\/\/Documentation: https:\/\/nodejs.org\/api\/util.html#utilinspectobject-options\r\n<\/pre>\n<p>2.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">JSON.stringify(value, replacer, space)\r\nconst obj = {}\r\n\r\nconsole.log(JSON.stringify(obj, null, \"\\t\"));\r\n\r\n\/\/ \"\/t\" would format the output with a tab in each line of property output\r\n\r\n\/\/Documentation: https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/JSON\/stringify\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Basic console.log will not go through long and complex objects, and may decide to just print [Object] instead. Two of the suitable ways to print the object with nested properties are exemplified below: 1. util.inspect(object[, options]) const util = require(&#8216;util&#8217;), const obj = {} \/\/ some complex object console.log(util.inspect(obj, {depth: null})); \/\/{ depth: null } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-8364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8364"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=8364"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8364\/revisions"}],"predecessor-version":[{"id":8366,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/8364\/revisions\/8366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/8476"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=8364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=8364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=8364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}