zoplonix
zoplonix

Reputation: 1072

Is it possible to debug node js code that runs before the debugger attaches?

Using the instructions found here I have setup Visual Studio Code to debug my nodejs code.

But it takes the debugger a few seconds to attach to node. And during that few seconds the code just runs.

So a file like this, with a breakpoint on line 1:

• 1 console.log('')

Will never break because it quits before the debugger attaches.

I can quickly ^c the code then restart and sometimes catch the debugger but this is unreliable.

Is there an event I can wait for in my code so that I know the debugger is attached and it is safe to continue?

Or is there a better configuration for doing this?

Upvotes: 1

Views: 66

Answers (1)

zoplonix
zoplonix

Reputation: 1072

Yes, using the --inspect-brk option for node instead of --inspect.

so when running your code it would look something like this

node --inspect-brk server.js

Upvotes: 2

Related Questions