Use Node.js command line debugger for child process?

I am using a Node client debugger, for example:

node debug myscript.js

But this process gives birth to a child using:

var child = require ("child_process"). fork (cmd, args);

Is there a way for this child to ALSO run in debug mode?

+7
source share
3 answers

Yes. You must create your process in the new port. There is a workaround for debugging with clusters, just as you can:

var debug = process.execArgv.indexOf('--debug') !== -1; if(debug) { //Set an unused port number. process.execArgv.push('--debug=' + (5859)); } var child = require("child_process").fork(cmd, args); 

.... the debugger is listening on port 5859

+3
source

No problem. All you have to do is send the debug Sig to the running process. Look at node-inspector docs find find for Enable debug mode

I can't tell you how to do debug-brk, I'm not sure what you can, but you can always do something from code

while (true) {debugger}

So you can catch the debug statement and then exit the loop manually. Dirty i know =)

0
source

Otherwise, this will result in debugging the child on a free port:

 // Determine if in debug mode. // If so, pass in a debug-brk option manually, without specifying port. var startOpts = {}; var isInDebugMode = typeof v8debug === 'object'; if(isInDebugMode) { startOpts = {execArgv: ['--debug-brk']}; } child_process.fork('./some_module.js', startArgs, startOpts); 
-one
source

All Articles