Chapter 11. Debugging: Designing for introspection and resolving issues

 

This chapter covers

  • Handling uncaught exceptions
  • Linting Node applications
  • Using debugging tools
  • Profiling applications and investigating memory leaks
  • Using a REPL to investigate a running process
  • Tracing system calls

Understanding how errors are generated and handled in any given platform is paramount to building stable applications. Good error introspection and tests that are built-in are the best offense for debugging issues later on. In this chapter we focus on how to prepare for and what to do when things go south.

Maybe your process keeps crashing or it’s using more memory than you expected. Perhaps it’s stuck at 100% CPU usage. We’ll look at debugging solutions for these and other problems you may encounter in your Node applications.

In the first part we’ll cover Node application design for error handling and detection. In the second half we’ll look at debugging specific types of problems.

11.1. Designing for introspection

When we design applications, we need to be thinking about how we’ll handle errors. Relevant error logging and intervention takes thought. It also takes a good understanding of where errors can occur in order to trap them. Throughout this book, we’ve covered various forms of errors that can happen in Node applications. Let’s cover all the types here.

11.1.1. Explicit exceptions

11.2. Debugging issues

11.3. Summary