Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inspecting variables using node's built-in debugger?

I am trying to use the node debugger. I am running node debug server to run my server. Then I have:

... var Workspace = mongoose.model('Workspace'); debugger; 

At this point, as expected, when I run this code the debugger pops up. However, I would expect it to have all of the current variables set, like it happens in Chrome's own debugger.

But:

break in hotplate/node_modules/bd/lib/bd.js:133 132  133   debugger; 134  135   // Delete the ID and the version since there's no point, debug> Workspace ReferenceError: Workspace is not defined 

So... how do I actually inspect the current variables?

Bonus question: is there ANY way to use Chrome's developers tools (CTRL-J) so that it connects to the node and works that way? (I am aware of node-inspector, but it's very outdated and...)

like image 718
Merc Avatar asked Dec 18 '12 04:12

Merc


People also ask

How do I use BRK inspect?

The port 9229 is the default debug port of the --inspect and --inspect-brk options. To use a different port (for example 12345 ), add it to the options like this: --inspect=12345 and --inspect-brk=12345 and change the port attribute in the launch configuration to match.

How do I use Nodejs debugger?

Built-in Debugger Start node debug script_name. js to start your script under the builtin command-line debugger. Your script starts in another Node. js process started with the --debug-brk option, and the initial Node.


2 Answers

Use repl command ( see third example in docs )

break in hotplate/node_modules/bd/lib/bd.js:133 132  133   debugger; 134  135   // Delete the ID and the version since there's no point, debug> repl Press Ctrl + C to leave debug repl > Workspace 

Update: bonus question - https://github.com/c4milo/node-webkit-agent

like image 61
Andrey Sidorov Avatar answered Oct 14 '22 06:10

Andrey Sidorov


The answer to the bonus question has changed in 2018.

Run node inspect foo.js.

Visit chrome://inspect and in the list of devices you should see an entry that says Target (<process.version>) with an accompanying inspect link.

It looks like this: enter image description here

like image 45
Andy Gaskell Avatar answered Oct 14 '22 04:10

Andy Gaskell