Created
January 8, 2017 08:44
-
-
Save impaler/bc9b3befb3bd929c90f921da652aa3a1 to your computer and use it in GitHub Desktop.
Debug node child_process fork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Debug me with a tool like webstorm nad the child process will step in with your breakpoints :) | |
const fork = require('child-process-promise').fork | |
const debug = typeof v8debug === 'object' | |
export async function forkBin (args, debugPort) { | |
debugPort = debugPort || 40894 | |
let execArgv = debug ? ['--debug-brk', `--debug=${debugPort}`] : [] | |
const forkPromise = fork(binPath, args, { | |
execArgv | |
}) | |
var childProcess = forkPromise.childProcess | |
childProcess.on('close', () => { | |
childProcess.kill() | |
}) | |
childProcess.on('exit', () => { | |
childProcess.kill() | |
}) | |
childProcess.on('message', function (m) { | |
console.log('PARENT got message:', m) | |
}) | |
childProcess.on('data', function (m) { | |
console.log('PARENT got data:', m) | |
}) | |
return forkPromise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment