Why is the Node debugger "break on first line" a thing?

2.4k views Asked by At

I thought the reason the new VS Code debugger stopped on the 'use strict'; in my file was because of some weird deprecatory behaviour in new versions of Node, or else because my code had some weird error in it.

Then I realised that "break on first line" is a thing, and one that people want. Why on earth is this a thing? I know that my script has a first line, thank you very much. I'd have bigger problems if it didn't. So why does the debugger need to do this?

3

There are 3 answers

1
Alexander O'Mara On BEST ANSWER

The reason "break on first line" is a feature, is so that you can run your application, and have it stop on the first line before continuing.

This allows you to attach a debugger before Node has executed some of the code. This enables you to debug the very first lines of code, set more breakpoints, or step over the lines of code whenever you are ready.

This is actually a pretty common feature in a debugger, especially if you don't necessarily have a way to set breakpoints before you run the code.

0
Ben Bieler On

Now a toggle for this exists:

--inspect vs --inspect-brk
2
utkarsh On

In launch.json there is a property stopOnEntry which is set to true by default. If you don't want to Node Debugger to "break on first line" set this property to false.