child-process-debug

Convenience methods for debugging child-process

child-process-debug

Convenience methods for debugging child processes in Node.JS. Child processes will be started with --debugif the parent was started with --debugand the children will each get their own increasing port number based off the parent's port number. The default port is 5858. If you add --debug-brkthat will also get passed to the children.

Example

var childProcessDebug = require('child-process-debug');

for (var i = 0; i < 4; i++) {
    //if this script wasn't run with --debug this will spawn node example.js [0-3]
    //if this script was run with --debug, this will spawn node --debug=[5859-5862] example.js [0-3]
    childProcessDebug.spawn(['example.js', i]);
}

Methods

spawn([command][, args][, options])

This takes the exact same arguments as child_process.spawnand if the parent had debugging turned on (via --debug), it'll turn on debugging for the spawned child. commandis also optional (unlike child_process.spawn) and defaults to process.execPath.

The ChildProcess returned from spawn will have a property called debugPortindicating the debug port chosen for that child or undefined.

fork(modulePath [, args][, options])

This takes the exact same arguments as child_process.forkand if the parent had debugging turned on (via --debug), it'll turn on debugging for the spawned child. Return is the same as spawnabove.

nextPort()

Returns the next debug port that comes after the current process's debug port. If the current process doesn't have debug turned on then this will return undefined. This is useful if you're not using spawnand want to specify the --debug=portargument yourself.

exitWithParent(child)

Kill's the spawned child when the parent dies. This will not work if the parent is killed with SIGKILL.

port()

Returns the current process's debug port or undefined if debug is not turned on.

debugBreak()

Returns true if the current process has the flag --debug-brk.

By James Hartig

Repository

https://github.com/fastest963/child-process-debug


上一篇:quadric-chimp
下一篇:nightwatch-api

相关推荐

官方社区

扫码加入 JavaScript 社区