I want to be able to drop a debugger statement (or something similar) right into my code and get a REPL when I run my tests so I can interact with my code to debug stuff.
I understand that Node (via V8) supports the debugger statement out of the box, but you have to run your code with certain flags (via node debug or node --debug or node --debug-brk -- I don't really understand the differences).
Mocha has these same flags as well, and when I run mocha debug I indeed get a debugger prompt in my terminal:
< Debugger listening on port 5858
connecting to port 5858... ok
break in node_modules/mocha/bin/_mocha:5
3 */
4
> 5 var program = require('commander')
6 , path = require('path')
7 , fs = require('fs')
debug>
But the breakpoint is in Mocha's code, not my breakpoint. This blog post says you're supposed to type run then continue to get to your breakpoint, but when I enter run it tells me "App is already running..." and when I enter continue it tells me "SyntaxError: Illegal continue statement".
It says "listening on port 5858" -- do I need to open a separate connection to that port from somewhere, like a browser or another terminal session?
I've seen some things about node-inspector, but I like to stay in the terminal as much as possible so I prefer a way to do this without opening a browser.
I'm new to JS, so please ELI5 :)
Also, if it's relevant, I'm actually using io.js, not Node proper
When the node/iojs debugger first starts up and connects it always breaks on the first line of whatever the script was that was passed into the interpreter.
Since you're already running your app, you do not need to type run here, but you can just type c to continue execution until your breakpoint has been it.
run is useful if the program terminates while you're in the debugger -- you can start it up again! (You can also do restart to restart the program within the debugger).
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