Running my static generator in the VSCode debugger

2025-05-07 18:46:32 +01:00 by Mark Smith

I configured the VSCode debugger to run my static site generator. It's been a while since I've been debugging like this. It's awesome to finally see the code running with all the debug tools. Makes it so much easier to get back into code that I wrote years ago. I wanted to make a quick note of it here, it's one of those things that you configure then don't think about for ages. Now I can refresh my brain with this blog post.

Crucially VSCode supports debugging programs launched via npm. Since I use npm scripts to run my code locally and in Github actions, I wanted to use the same method in the debugger.

The trick to getting it working was to use the npm launch configuration, and to also add a new 'debug' npm script, which was a copy of the existing 'build' npm script but with the additional '--inspect' node arg. Then when you run the debugger in VSCode, and after you have set a breakpoint somewhere near the top of your code, the command line window opens, and VSCode runs the program, halting at your breakpoint and you can step through the code, examining variables, callstacks and use all sorts of other cool tools. #

For enquiries about my consulting, development, training and writing services, aswell as sponsorship opportunities contact me directly via email. More details about me here.