Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Node.js command line debugger on child process?

I use the Node client debugger, like so:

node debug myscript.js

But this process spawns a child using:

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

Is there a way for this child to ALSO be started in "debug" mode?

like image 220
user836003 Avatar asked Feb 29 '12 21:02

user836003


People also ask

Can we use debugger in node js?

To use it, start Node. js with the inspect argument followed by the path to the script to debug. The debugger automatically breaks on the first executable line. To instead run until the first breakpoint (specified by a debugger statement), set the NODE_INSPECT_RESUME_ON_START environment variable to 1 .

How does Nodejs handle child process?

Usually, Node. js allows single-threaded, non-blocking performance but running a single thread in a CPU cannot handle increasing workload hence the child_process module can be used to spawn child processes. The child processes communicate with each other using a built-in messaging system.


1 Answers

Yes. You have to spawn your process in a new port. There is a workaround to debug with clusters, in the same way you can do:

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);

.... debugger listening on port 5859

like image 190
davidforneron Avatar answered Nov 15 '22 09:11

davidforneron