How to start the debugger
For debugging node applications, we have to only run a debug command. Here for a quick demonstration, I have used Open-Event-Webapp fold.js code.
Suppose there is a problem in the script file and we have to debug it. All we have to do is to run the debug command from the directory containing the file.
node debug ./fold.js
The output screen will show something like this:
This brings us into the debug mode. When we are in debug mode, we can try various commands like ‘n’ for next, ‘s’ for the step into a function, ‘list(k)’ where k is the number of lines of the code you want on the screen.
The ‘n’ command always takes us to next instruction, hence in long codebases, it is always recommended to use ‘c’ or Continue Execution command for going to the next breakpoint.
To set the breakpoint, we can use the command:
setBreakpoint() or sb()
The snapshot shows the output once the breakpoint is set. We can check the values at the breakpoint by using command repl.
Debugging the code correctly can save a lot of time and effort. These techniques provided by the debugger are necessary to learn.
You must log in to post a comment.