I want to be able to run a whole script in node
during debugging with node-inspector
and Web Inspector. - I don't want to step through the individual JavaScript calls.
(My PowerShell Instructions)
PS C:\Users\JK> node-inspector
info - socket.io started
visit http://0.0.0.0:8080/debug?port=5858 to start debugging
...
==[In another PowerShell instance:]==
PS %> node —debug-brk myscript.js
debugger listening on port 5858
I'm writing a node script. In this script I console.log
a lot of objects in order to be able to explore them during the debugging process. But the simple static textual console output isn't really nice - You can't fold and expand your object's properties or get the source code of a function:
(For Example)
{ [Function: Xy]
a: [Function],
b: 8.2,
c: [Function],
d: [Circular],
e: '2011-11-11' }
So I decided to use Web Inspector with node-inspector
in order to get a good object browse experience (because of Web Inspector's nice output formatting).
(Structure of My Script)
var fs = require('fs');
fs.readFile('myfile', function (err, data) {
if (err) {
throw err;
}
//My Script...
console.log(something);
});
console.log()
calls are executed in a callback function of
require('fs').readFile()
. I won't get there just with "normal"
steps.node —debug myscript.js
instead of node —debug-brk myscript.js
because then Inspector throws Error: connect ECONNREFUSED
Is node running with --debug port 5858?
because the script runs too fast)(Web Inspector Interface)
Thanks. - (I hope it's clear what I wanted to ask. - Please write a comment if it isn't.)
You have a couple options.
Using --debug-brk
:
Start your script, let it stop on the first line.
In the Script pane, click the line number inside the callback (line 4 in this example).
Click "Continue" (the "|> icon above the right-hand panel).
Using --debug
:
debugger;
to your callback. This will stop the
debugger at that point. Click "|>" when you're done.