Debug Your Node.js App in 60 Seconds

John Papa
John Papa
Dec 11, 2018 · 2 min read

Setting up debugging can be a chore. It can make you feel like console.log isn’t so bad after all. Right? While I enjoy a good console.log as much as anyone, I’d much rather debug with zero configuration of my app. Wouldn't you?

Sketchnote of Debugging Node.js in 60 Seconds

Visual Studio Code (aka VS Code) has changed the game on Node.js debugging. There is a feature called Node: Auto Attach (you can learn more about it here in the docs). Or keep reading — this will only take a minute.

When you enable this feature, you can run your node app from a command line, from an npm script, or from a tool that runs one of those. Just make sure you add the Node Inspector flag to let Node know you are planning on debugging. Once you do this, the debugger lights up in VS Code!

Auto-Attach the Debugger to Node.js Apps with VS Code

Step by Step

Search for “auto attach” and you’ll see a setting for Node: Auto Attach. Go ahead and turn that on.

Now run your Node.js app from your favorite command line whether that be integrated terminal, external terminal, or using a magic wand (well, if you have a magic wand, you likely don’t need debugging 😀).

node --inspect= server.js

Now when you launch your app with the --inspect flag the debugger attaches to your app in VS Code! From here you can set breakpoints, step through your code, and have all the great debugging goodness!

You can learn more about this feature from this link in the VS Code docs.

Like this tip? Clap and I’ll share more quick tips in the future.


Node.js Collection

Community-curated content for the millions of Node.js

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store