Search code examples
node.jsvisual-studio-codenode-debugger

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


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?


Solution

  • 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.