Skip to content

Instantly share code, notes, and snippets.

@impaler
Created January 8, 2017 08:44
Show Gist options
  • Save impaler/bc9b3befb3bd929c90f921da652aa3a1 to your computer and use it in GitHub Desktop.
Save impaler/bc9b3befb3bd929c90f921da652aa3a1 to your computer and use it in GitHub Desktop.
Debug node child_process fork
// 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