vicneanschi vicneanschi - 1 year ago 261
Node.js Question

How to debug child Node.JS process in Visual Studio Code?

How to debug child Node.JS process in VS Code?

Here is the example of the code that I'm trying to debug:

var spawn = require('child_process').spawn;
var scriptPath = './child-script.js';
var runner_ = spawn('node', [scriptPath]);

Answer Source

You can easily add a new launch configuration to launch.json that allows you to attach to a running node instance with a specific port:

        "name": "Attach to Node",
        "type": "node",
        "address": "localhost",
        "port": 5870,

Just make sure you fork/spawn your node process with the --debug or --debug-brk argument.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download