Node.js Debugging Deepdive with Bradley Farias, Fedor Indutny and Thorsten Lorenz.

Node.js Debugging Tools

Node Report delivers a human-readable diagnostic summary, written to file.
llnode is a Node.js C++ LLDB plugin.
Debugger API
node --inspect flag
node-inspect CLI debugger

llnode can be used for post-mortem or live debugging. Designed for fullstack debugging including C++ and all JavaScript functions/objects.

node --inspect flag debugs Node process with Chrome devtools to do heap snapshots, profiles and so on. Bundled now with Node.
node-inspect is a front-end to the --inspect back-end that bundled with Node. Allows debugging Node process as easy as debugging browser.

--prof and --prof-process provides profiling of Node process.

If a problem of JavaScript logic and need more than console.log, use node --inspect as starting point to follow JavaScript.
If find that problem is lower in the stack, then need to use llnode to debug C++ (or C++ profile tools).

Post-mortem debugging is used to understand crashed application. Kernel is configured to save a core dump which contains all of Node memory including V8 and C++ heaps.

Using --inspect on a script that runs to completion, dubugger won't have time to attach to script before completion.
So also need to pass --debug-brk to insert break, which inserts break point on very top line.

Need to name function declarations if debugging memory, otherwise will be unnamed in memory snapshot.

Async Hooks can be used to hook into the lifetime events for any asynchronous resource in Node. Challenge is in dealing with the amount of data generated.

Promises obfuscate a lot of complexity that could lead to problems. Callbacks work cleaner with Node.

Tracing API allows Node to emit events for certain parts of the code.

Time travel debugging is available in Node-ChakraCore (Node ported to Microsoft's ChakraCore JavaScript engine).