I am having the following issue - I am attempting to debug/set a breakpoint in code that is run using the vm module. The only way that I have found to accomplish this is by putting a debugger statement:
// client code, loaded in the vm module
function printMessage() {
debugger;
return 56;
}
printMessage();
Is there any other way to accomplish this? Preferably using tools such as node-inspector?
EDIT: Found a solution - by passing a string for "filename" to the executing function from vm. For example:
vm.runInThisContext(codeToRun, "someFilename.js");
this way the debugger "figures out" where exactly the code came from.
As you mention, node-inspector
is a good candidate for this task. Can't you just start node-debug someFilename.js
and set your breakpoints directly in the UI ?
Another alternative is to use debugger
with and then run node debug someFilename.js
and use commands like setBreakpoint('someFilename.js', 10)
You can find more information in the node documentation: https://nodejs.org/api/debugger.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With