I'm trying to debug a Node script forked using child_process's fork method using VSCode.
I have read almost all of the related docs, discussions but without any success. I'm not sure what am I doing wrong.
For your reference, I have posted a my sample code as a gist and is available at: https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543
It contains the three files: parent.js, child.js and launch.json (vscode configuration). I'm trying to setup 2 breakpoints: one at https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543#file-child-js-L4 and another at https://gist.github.com/dpnishant/43096af3fecde4ec9fdea7c1d81cf543#file-parent-js-L16.
Case-1
When I click "Start Debugging" using the "Launch Program" config, I'm able to hit the line 16 breakpoint on parent.js but the other breakpoint in child.js is never hit.
Case-2
When I click "Start Debugging" using the "Attach" config, I get the following error:
Debugging with legacy protocol because Node.js version could not be determined (Error: connect ECONNREFUSED 127.0.0.1:9999)
Case-3
When I start node parent.js in Terminal and immediately switch to VSCode to click "Start Debugging" using the "Attach to Process" config and choose the node process with the "child.js" script, I'm able to hit breakpoint on line 4 in child.js but by that time, the loop has already started and it's already late.
So my requirement is a method through which I can start my parent.js script and hit the desired breakpoint in child.js as soon as it starts execution.
Can someone point out to me where am I doing wrong? And what would be a optimum solution for my use-case?