55

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...)

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Merc
  • 16,277
  • 18
  • 79
  • 122

3 Answers3

88

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

Andrey Sidorov
  • 24,905
  • 4
  • 62
  • 75
  • What about the bonus question? :D – Merc Dec 18 '12 at 09:19
  • not sure if there is readily available solution other then node-inspector but you could try to use chrome developer tools remote debugger - https://developers.google.com/chrome-developer-tools/docs/remote-debugging – Andrey Sidorov Dec 18 '12 at 13:33
  • 2
    any idea how to get it to output the full variable instead of truncating it? – NSjonas May 06 '16 at 19:23
  • 2
    is that a string? V8 debugger agent only returns first 80 chars of a string, so you have to select other part ( `mystring.slice(123)` - substring starting from index 123 ) or ask debuggee to output it ( `console.log(mystring)` ) – Andrey Sidorov May 07 '16 at 12:16
5

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

Andy Gaskell
  • 31,495
  • 6
  • 74
  • 83
1

You can use exec to inspect variables. It's much faster and you don't have to switch to a REPL.

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> exec workspace
Stanley Ulili
  • 702
  • 5
  • 7