Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Last active June 27, 2024 14:49
Show Gist options
  • Save DavidWells/808f07b67885ecfecea39b8ce17bf7e9 to your computer and use it in GitHub Desktop.
Save DavidWells/808f07b67885ecfecea39b8ce17bf7e9 to your computer and use it in GitHub Desktop.
How to easily debug node.js script
const { inspect } = require('util')
/* Log out everything in the deep array/object */
function deepLog(obj) {
console.log(inspect(obj, {showHidden: false, depth: null, colors: true}))
}
function myScript(input) {
/* Lots of crap */
/* And lots more crap */
const myThingINeedToCheck = {stuff: 'Giant object value'}
/* The below //* can toggle on and off the debug block by removing first "/" */
//*
console.log('myThingINeedToCheck')
deepLog(obj)
// Kill process to inspect that big ol' beast
process.exit(1)
/**/
/* Lots more of crap */
/* .... */
}
myScript('foobar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment