Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Pausing at a Line With node inspect

Key Points

Pausing at a Line With node inspect

  • Joan’s November export has three bad rows, and both imports report them in the same four lines. But what did line 3’s amount field hold?
  • In Python, you’d put breakpoint() right after the amount is converted, and the usual run stops at pdb’s prompt

Porting breakpoint()

  • The port’s matching line is a debugger statement, a keyword, not a call, after Number() converts the amount
  • Run the port with node, as usual. What does the terminal show?
  • The report: the same four lines as before, and the exit code is 1

Why Nothing Stopped

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 Joan’s November export has three bad rows, and both imports report them in the same four lines. But what did line 3’s amount field hold? In Python, you’d put breakpoint() right after the amount is converted, and the usual run stops at pdb’s prompt.

00:18 The port’s matching line is a debugger statement, a keyword, not a call, after Number() converts the amount. Now run it with node, as usual.

00:28 What does the terminal show? Your turn: pause the video and predict.

00:38 The report. The same four lines as before, and the exit code is one.

00:46 Nothing paused, and there’s no error or warning. A debugger statement pauses only when a debugger is attached to the program. Without one, it does nothing.

00:55 And plain node doesn’t attach one, where Python’s breakpoint() starts pdb by itself. So the fix isn’t in the code: you start the program under a debugger.

01:08 Node’s terminal debugger comes built in: put inspect between node and the file name. node inspect starts your program as a second Node process, with a debugger port on your own machine, under a random id.

01:21 Angle-bracket lines are what that process prints. The debugger connects and attaches, then stops on line one, Break on start, as python -m pdb does and breakpoint() never does.

01:35 cont runs to your debugger statement and lists the lines around it, marking line 46. exec, or p, runs an expression in the paused function, like pdb’s p: exec amountText gives the string '50.00', and exec amount the number 50.

01:55 But a bare name is a ReferenceError here.

01:59 next runs one line, to the amount check on line 47. cont runs to the statement again. exec an array of three variables to see which row it’s on: line 3, donor D-108, and the amount field held 'n/a'.

02:15 Watch out: keep typing cont, and it stops on lines 5, 6 and 7 of the export, never on line 4, whose field check throws: no stop means the code never ran.

02:29 .exit ends the program at once: no question, no report. The rest line up with pdb, except three. For pdb’s r, use out: typing r here restarts the program.

02:42 watch() shows an expression at every stop; display, only when it changes in the same call. And interact becomes repl, a read-eval-print loop in the paused code.

02:55 So don’t count on the statement alone: start the program under a debugger, where the statement marks the stop and exec reads the values. It comes out before you commit.

03:05 Next up, Debugging in Chrome DevTools and VS Code, a text lesson. You’ll pause in a graphical debugger, set breakpoints with a click, and stop only on the row you want.

Become a Member to join the conversation.