Node.JS – View contents of object in console

Use the NodeJS Utility Module to display the contents of an object in the console logs
Use the NodeJS Utility Module to display the contents of an object in the console logs

When using Node.JS and you need to write to your log files what the contents of an OBJECT is, simply do the following:

  • Require the Utility module at the setup of your script.  Put this at the top where you are requiring all of your other modules.
  • Then, where you want to view the contents of your object, simply use console.log with the utility.inspect function.  Here is an example:

Simple as that!

The Utility module offers many other features, but that’s to be explored another day.