I've seen this question asked of other platform/languages - any ideas? I'd like to do something like:
if (detectDebug()) { require('tty').setRawMode(true); var stdin = process.openStdin(); stdin.on('keypress', function (chunk, key) { DoWork(); } } else { DoWork(); }
I'd like to be able to toggle keyboard input as a start for the script when debugging so that I can have a moment to fire up chrome to listen to my node-inspector port.
***Quick update - I'm guessing I can actually use "process.argv" to detect if --debug was passed in. Is this the best/right way?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With