Node.js Debugging Tools
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-process provides profiling of Node process.
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.
--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.