← #67 Add a line break between inline elements
#68

Log the full object in NodeJS

Topics: NodeJS

Using the console.log method in NodeJS might not be ideal if the input has deep nested properties. It will replace the deep nested property with [Object].

Let's say that the person variable holds the information of a person. console.log(person) will produce the following output:

{
username: 'johndoe',
meta: {
firstName: 'John',
lastName: 'Doe',
profile: { address: [Object] }
}
}

To get rid of [Object], you can use the console.dir method to see the full object:

console.dir(person, { depth: null });
/*
{
username: 'johndoe',
meta: {
firstName: 'John',
lastName: 'Doe',
profile: {
address: { street: '123 Main St', city: 'AnyTown' }
}
}
}
*/

It's also possible to use the same technique mentioned in the Pretty format JSON tip which works in both NodeJS and browser environments.

More

Fix a typo or suggest an improvement
#69 Copy the full path of a file on macOS