Node Inspector is a debugger interface for Node.js applications that uses the Blink Developer Tools (formerly WebKit Web Inspector).
Since version 6.3, Node.js provides a built-in DevTools-based debugger which mostly deprecates Node Inspector, see e.g. this blog post to get started. The built-in debugger is developed directly by the V8/Chromium team and provides certain advanced features (e.g. long/async stack traces) that are too difficult to implement in Node Inspector.
The node-debug command will load Node Inspector in your default browser.
NOTE: Node Inspector works in Chrome and Opera only. You have to re-open
the inspector page in one of those browsers if another browser
is your default web browser (e.g. Safari or Internet Explorer).
Node Inspector works almost exactly as the Chrome Developer Tools. Read the
excellent
DevTools overview
to get started.
The Blink DevTools debugger is a powerful JavaScript debugger interface.
Node Inspector supports almost all of the debugging features of DevTools, including:
Navigate in your source files
Set breakpoints (and specify trigger conditions)
Step over, step in, step out, resume (continue)
Inspect scopes, variables, object properties
Hover your mouse over an expression in your source to display its value in
a tooltip
Edit variables and object properties
Continue to location
Break on exceptions
Disable/enable all breakpoints
CPU and HEAP profiling
Network client requests inspection
Console output inspection
Cool stuff
Node Inspector uses WebSockets, so no polling for breaks.
Set breakpoints in files that are not loaded into V8 yet - useful for
debugging module loading/initialization.
Embeddable in other applications - see Embedding HOWTO
for more details.
Known Issues
Be careful about viewing the contents of Buffer objects,
each byte is displayed as an individual array element;
for most Buffers this will take too long to render.
While not stopped at a breakpoint the console doesn't always
behave as you might expect. See the
issue #146.
Break on uncaught exceptions does not work in all Node versions,
you need at least v0.11.3 (see
node#5713).
The debugged process must be started with --debug-brk, this way the script is paused on the first line.
Note: node-debug adds this option for you by default.
I got the UI in a weird state.
When in doubt, refresh the page in browser
Can I debug remotely?
Yes. Node Inspector must be running on the same machine, but your browser can be anywhere.
Just make sure port 8080 is accessible.
And if Node Inspector is not running on your remote machine, you can also debug it as long as your local machine can connect it.
In this way, you must launch Node Inspector with --no-inject which means some features are not supported such as profiling and consoling output inspection.
So how to debug remote machine with your local Node Inspector?
Note that the array items are interpreted as regular expressions.
UI doesn't load or doesn't work and refresh didn't help
Make sure that you have adblock disabled as well as any other content blocking scripts and plugins.
How can I (selectively) delete debug session metadata?
You may want to delete debug session metadata if for example Node Inspector gets in a bad state with some
watch variables that were function calls (possibly into some special c-bindings). In such cases, even restarting
the application/debug session may not fix the problem.
Node Inspector stores debug session metadata in the HTML5 local storage.
You can inspect the contents of local storage and remove any items as
needed. In Google Chrome, you can execute any of the following in the JavaScript console:
// Remove allwindow.localStorage.clear()// Or, to list keys so you can selectively remove them with removeItem()window.localStorage// Remove all the watch expressionswindow.localStorage.removeItem('watchExpressions')// Remove all the breakpointswindow.localStorage.removeItem('breakpoints')
When you are done cleaning up, hit refresh in the browser.
Node Inspector takes a long time to start up.
Try setting --no-preload to true. This option disables searching disk for *.js at startup.
Code will still be loaded into Node Inspector at runtime, as modules are required.
How do I debug Mocha unit-tests?
You have to start _mocha as the debugged process and make sure
the execution pauses on the first line. This way you have enough
time to set your breakpoints before the tests are run.
$ node-debug _mocha
How do I debug Gulp tasks?
If you are running on a Unix system you can simply run the following command.
The $(which ..) statement gets replaced with the full path to the gulp-cli.
$ node-debug $(which gulp) task
If you are running on Windows, you have to get the full path of gulp.js
to make an equivalent command:
Making Node Inspector the best debugger for node.js cannot be achieved without
the help of the community. The following resources should help you to get
started.
Port to listen on for Node Inspector's web interface.
node-debug
--debug-brk
-b
true
Break on the first line. (node --debug-brk)
--nodejs
[]
Pass NodeJS options to debugged process. (node --option={value})
--script
[]
Pass options to debugged process. (node app --option={value})
--cli
-c
false
CLI mode, do not open browser.
node-inspector
--save-live-edit
false
Save live edit changes to disk (update the edited files).
--preload
true
Preload *.js files. You can disable this option to speed up the startup.
--inject
true
Enable injection of debugger extensions into the debugged process. It's possible disable only part of injections using subkeys --no-inject.network. Allowed keys : network, profiles, console.
--hidden
[]
Array of files to hide from the UI, breakpoints in these files will be ignored. All paths are interpreted as regular expressions.