Last active
June 27, 2024 14:49
-
-
Save DavidWells/808f07b67885ecfecea39b8ce17bf7e9 to your computer and use it in GitHub Desktop.
How to easily debug node.js script
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') | |
/* 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