I’ve never found the time to investigate better ways to debug Node.js than using
console.log. So I’ve decided to do some googling and testing, and write-down here the result as a memo.
Just one little step better than using
util.inspect function generates a human-readable representations of the parameter specified. It’s like Ruby Object.inspect, but with some extra features.
I like using it like this:
// inspect the Boolean function constructor
// options: show hidden fields, 1 depth of recursion, use ANSI colors
util.puts(util.inspect(Boolean, true, 1, true));
In my terminal, this is the output:
A proper debugger
node-inspector. It’s like a chain:
node-inspector (visual UI) -> Node.js debugger -> V8 debugger
This combination is really powerful. node-inspector uses the WebKit debugger as a UI. Here is a screenshot of me, inspecting an Express.js response object:
It’s also very easy to use. Just run
--debug param, start
node-inspector, and open a browser.
node-inspector can also be hooked to an existing process and can be easily used to do remote-debugging.