3

I'm using node-debug and know which file and line for which I want to set a breakpoint.

Here's what happens:

debug> setBreakpoint('./services/search.js', 359) Warning: script './services/search.js' was not loaded yet. You can't list source code right now

Why can't I "list source code"? How can I add a breakpoint dynamically (without editing the source code to add debugger)?

I tried other tools for debugging, and would love to use Chrome Dev Tools, but don't think it's possible since our project is stuck on v0.12.3.

Also, some options are limited/tricky because I'm using Vagrant with a headless VM.

Max Heiber
  • 14,346
  • 12
  • 59
  • 97
  • 1
    [node-inspector](https://www.npmjs.com/package/node-inspector) should work with 0.12. (in node >= 6, use the built in `node --inspect` instead.) – josh3736 Nov 21 '16 at 20:58
  • @josh3736 I tried node-inspector and it doesn't seem to be working correctly. If I make a simple program with a console.log on the first line, nothing is logged. And, in the VM, if I curl localhost:8080, there's no response – Max Heiber Nov 21 '16 at 21:04
  • With node-inspector, I'm pretty sure `console.log`ed things show up in stdout (like usual), not in the inspector console. Additionally, your test script would likely complete before you have a chance to connect the debugger. I'd run `node-inspector` in one window, then `node --debug-brk myscript.js` in another. Then you can open the inspector in a web browser and begin execution. – josh3736 Nov 21 '16 at 21:09
  • @josh3736 with node-inspector, nothing shows up in stdout. And my small test script has `debug` lines, so no need for --debug-brk . I'm trying this with a tiny script: `var x = 2; console.log(x); debugger; x = 3; console.log(x);console.log('done');` Also trying this with a large Express application. – Max Heiber Nov 21 '16 at 21:15
  • 1
    `debugger` statements have no effect if there's no debugger **attached** at the moment the line is executed -- so yes, `--debug-brk` is necessary with your test script. (Although it is strange that your logs aren't showing up on stdout... `process.stdout.write`?) – josh3736 Nov 21 '16 at 21:53

1 Answers1

0

This is still a problem in node 6.

There is precious little information about it on the net, which is a shame.

However, node --inspect and then using Chrome does work.

SCdF
  • 57,260
  • 24
  • 77
  • 113