Last active
March 14, 2022 09:07
-
-
Save kieranbarker/c2679edaf28bf8dc10d77956ea91da6a to your computer and use it in GitHub Desktop.
A demo of the util.inspect() method in Node.js.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { inspect } = require('util'); | |
const restaurants = [ | |
{ | |
name: 'Nando\'s', | |
menus: { | |
starters: [ | |
{ name: 'Halloumi Sticks & Dip', price: 425 }, | |
{ name: 'Houmous with PERi-PERi Drizzle', price: 425 }, | |
{ name: 'Sweet Potato Wedges with Garlic PERinaise', price: 425 } | |
], | |
mains: [ | |
{ name: '1/4 Chicken', price: 425 }, | |
{ name: '1/2 Chicken', price: 795 }, | |
{ name: 'Whole Chicken', price: 1450 } | |
], | |
desserts: [ | |
{ name: 'Choc-A-Lot Cake', price: 475 }, | |
{ name: 'Naughty Nata', price: 195 }, | |
{ name: 'Bottomless Frozen Yoghurt', price: 295 } | |
] | |
} | |
} | |
]; | |
console.log(inspect(restaurants, { | |
depth: Infinity, // Recurse up to the maximum call stack size. | |
colors: true, // Style the output with ANSI color codes. | |
compact: false // Display each object key on a new line. | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To try this, just run
node inspect.js
in the terminal. For more formatting options, check the official documentation.