How to programmatically detect debug mode in nodejs? How to programmatically detect debug mode in nodejs? node.js node.js

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


There is a node.js native support that using inspector.url() to check if there is active inspector, it just shows if process is debug mode or not currently. See doc for more.