10

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.

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.