How to programmatically detect debug mode in nodejs?

NodeJS creates a v8debug global object when running in debug mode: node debug script.js

So, a possible solution would be:

var debug = typeof v8debug === 'object';

For my use case, I use it because I want to avoid passing environment variables. My main node process starts child node processes and I want a node debug mainScript.js to trigger debug mode for children as well (again, without passing env variables to child processes)


I use this

var debug = typeof v8debug === 'object' 
            || /--debug|--inspect/.test(process.execArgv.join(' '));

which supports, --debug, --debug-brk, --inspect and --inspect=1234