Installation
Install Node Inspector as follows:
Starting the debugger
First, start your Node application as usual; for example:
Then run the debugger as follows:
This command starts Node Inspector and opens the interface at http://localhost:8080/debug?port=5858 in your default browser.
The slc debug
command provides a number of options. See slc debug for more information. For additional configuration information, see the Node Inspector README.
If you don't want to run your application with the slc debug
command, then you must use the node --debug-brk
command to halt application execution on the first line. This enables you to set breakpoints, step through the code, and debug the application.
Debugging a running application
To enable debugging on an application that is already running:
Get the PID of the node process, for example:
Send he application the USR1 signal
Using Node Inspector
Using Node Inspector to debug a Node application is similar to debugging client JavaScript in Chrome. See Chrome DevTools > Debugging JavaScript for more information.
Node Inspector loads and parses files during a debug session and automatically adds them to the GUI. This is useful for –debug-brk
and stepping through require()
calls.
Setting a breakpoint
To set a breakpoint in application code:
- Click on the "Show navigator" icon in the upper-left corner of the Node Inspector window to see a tree-list of all source files:
- Find the desired JavaScript file and double-click to open it.
- Click on the desired line number to set a breakpoint there.
Node Inspector highlights the line number in blue.
Press F10 to step through Javascript statements. Press F8 to resume script execution.
See the Chrome Developer Tools Guide for a walkthrough of other debugger features. Node Inspector is based on Chrome Developer Tools and most features work exactly the same.
Breakpoints and uncaught exceptions
Node Inspector restores breakpoints after restarting an application and remembers your breakpoints in the browser's local storage (HTML5). When you restart the debugger process, or start debugging the same application after several days, Node Inspector restores the breakpoints.
You can also break on uncaught exceptions. Node Inspector also provides integration with domains: exceptions handled by domain’s error handler are still considered uncaught. This feature requires Node.js v0.11.3 or greater.
Setting breakpoints in files not yet loaded
Ask Miroslav to clarify. Feature isn't specific to mocha: it can happen with other test frameworks, or even just general code. Separate the part that involves mocha as an example, and the general stuff,
Node Inspector enables you to set breakpoints in files that are not yet loaded into the V8 runtime.
To do this, for example for Mocha unit tests:
- Run mocha unit-test in any project with the
–debug-brk
option. - Launch Node Inspector.
- Look at source files of your unit tests and set breakpoints inside them.
- Resume execution when you have all breakpoints set up
- Wait for debugger to hit your first breakpoint.
Quick navigation shortcuts
You can navigate quickly by jumping to files and functions with keyboard shortcuts. For example, jump to file with search: Command+O
Jump to member function with search: Command+Shift+O
See Keyboard shortcuts for a complete list of shortcuts.
Display and edit variables
Hover a variable to display and edit its value, as illustrated below:
Support for source maps
Node Inspector supports source maps, enabling you to keep client-side code readable and debuggable even when combined and minified, without impacting performance. For example, you can compile CoffeeScript, LiveScript or TypeScript files with source-map option turned on. Node Inspector will show you the CoffeScript, LiveScript or TypeScript source instead of trans-piled JavaScript. Also, you set breakpoints in these files.
Re-execute functions with "Restart Frame"
Right-click on a call frame (stack frame) in the right sidebar and select the ”Restart frame” command to re-execute the current function from the beginning.
Keyboard shortcuts
Command | Mac | Windows / Linux |
---|---|---|
Next Panel | ⌘] | Ctrl-] |
Previous Panel | ⌘[ | Ctrl-[ |
Toggle Console | Esc | Esc |
Focus Search Box | ⌘F | Ctrl-F |
Find Next | ⌘G | Ctrl-G |
Find Previous | ⇧⌘G | Ctrl-Shift-G |
Console keyboard shortcuts
Command | Mac | Windows / Linux |
---|---|---|
Next Suggestion | Tab | Tab |
Previous Suggestion | ⇧Tab | Shift-Tab |
Accept Suggestion | Right | Right |
Previous Command / Line | Up | Up |
Next Command / Line | Down | Down |
Previous Command | ⌃P | |
Next Command | ⌃N | |
Clear History | ⌘K or ⌃L | Ctrl-L |
Execute | Return | Enter |
Debugger keyboard shortcuts
Command | Mac | Windows / Linux |
---|---|---|
Select Next Call Frame | ⌃. | Ctrl-. |
Select Previous Call Frame | ⌃, | Ctrl-, |
Continue | F8 or ⌘/ | F8 or Ctrl-/ |
Step Over | F10 or ⌘’ | F10 or Ctrl-’ |
Step Into | F11 or ⌘; | F11 or Ctrl-; |
Step Out | ⇧F11 or ⇧⌘; | Shift-F11 or Ctrl-Shift-; |
Edit Breakpoint | ⌃Click | Ctrl-Click |