Debugging Yeoman Generators with Visual Studio Code

In this article, I'll show you how I set up debugging with the Yeoman generator with VS Code. With this set up, building & testing Node.js web server.

Recently I was working on a Yeoman generator to easily stub out a Node.js web server locally that can serve HTTPS requests: generator-nodehttps.

I built this using Visual Studio Code and wanted to set it up so I could easily debug the generator while I was building it, setting breakpoints and the like. Always nice to have breakpoints, watches, call stacks and the ability to step through your code when you hit F5, right?

The VSCode site has a great explination on how to set up debugging for a Node.js application which applies to my goal beacuse Yeoman is built on Node. Check that out first…

The trick is how you configure the launch.json file within your project in Visual Studio Code to run Yeoman in debug mode. The way you do this is to make sure you tell Node to startup the Yeoman process on your machine, then pass in each argument you want it to call. Here’s what I used to make it work:

Now just set a breakpoint & hit F5 for some VSCode debugging goodness.

Andrew Connell
Developer & Chief Course Artisan, Voitanos LLC. | Microsoft MVP
Written by Andrew Connell

Andrew Connell is a web & cloud developer with a focus on Microsoft Azure & Microsoft 365. He’s received Microsoft’s MVP award every year since 2005 and has helped thousands of developers through the various courses he’s authored & taught. Andrew’s the founder of Voitanos and is dedicated to helping you be the best Microsoft 365 web & cloud developer. He lives with his wife & two kids in Florida.

Share & Comment