Making your JavaScript debuggable - NodeSource

The NodeSource Blog

You have reached the beginning of time!

Making your JavaScript debuggable

A few weeks ago, I presented a session at this year's Nodevember conference titled "making your JavaScript debuggable". The presentation covered some techniques and tools for making your JavaScript code easier to debug.

The slides are available at my slides site, and the video of my presentation is available at YouTube.

Here's a quick summary of the presentation, with links into the presentation and YouTube video. The presentation itself also contains a lot of links to the tools and libraries that I talk about.

  • code reading: presentation; YouTube 0:17

    Code readability is one of my pet peeves. We spend far more time reading code that we've already written, than writing code. Optimize for reading your code, not performance. You can always optimize for performance later, using pragmatic tools like CPU profilers. As Donald Knuth wrote:

    "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

  • logging: presentation; YouTube 8:38

    I'm a console.log()er. I admit it. Almost everyone is. But there's more to life than just console.log() ...

  • error handling: presentation; YouTube 16:18

    If you're lucky, your bugs will actually cause errors in your program that you'll notice right away, like throwing exceptions. And there are a few tools and techniques you can make use of, to give you even more information about your errors, when they occur.

  • actual debugging: presentation; YouTube 20:38

    In addition to using tools and techniques to make your code more debuggable, at some point you will want to actively debug your code. There are some extremely useful tools baked into Node.js itself: the built-in REPL and command-line debugger. And there are 3rd party tools available for GUI debugging, and generating CPU and memory profiles, to help find performance and memory-related problems.

    Using N|Solid, a product I work on at NodeSource, you can easily generate CPU profiles and heap snapshots (memory profiles) from your programs without any instrumentation of your code; just click some buttons in a web-based console. You can see a short demo of me using N|Solid in the YouTube video at [26:16]. N|Solid is free for development use; check my "Getting Started with the N|Solid Console" blog post for more information on installing and using N|Solid.

  • how can you help?: presentation; didn't get to it in the YouTube video

    Even though there are a number of tools to make your debugging experience more pleasurable, there's a lot of low fruit to be picked in the space of debugging tools for Node.js. Want to help build some? I noted a few ideas in the presentation, but don't hesitate to ask me about more! Strike up a conversation with me on Twitter; I'm @pmuellr - direct message is fine.

If you happen to be attending the Node Interactive conference, Dec 8-9 in Portland, OR, I'll be presenting an introduction to Node.js CPU and memory profiling, which I just lightly touched on in my Nodevember presentation. Use the discount code SPR20NJS for a nice discount on the registration cost.

The NodeSource platform offers a high-definition view of the performance, security and behavior of Node.js applications and functions.

Start for Free