Node Inspector Manager(NiM): An Extensive Debugger Interface for Nodejs Application

Node Inspector Manager(NiM) is a debugger interface specially developed for Nodejs applications that use the Blink Developer Tools, formerly WebKit Web Inspector.

Generally, it detects the URL that is generated when running node (locally) automatically with the inspect option in the DevTool. NiM manages the Chrome DevTools window pushes your ability to focus on what really matters in debugging your code.

While using Chrome DevTools inspector, NiM organizes your Nodejs development cycle for a clear workflow. It removes the need to copy/paste DevTools URL’s or continue opening/closing tabs/windows.

NiM avails you the option of automatically opening and closing Chrome DevTools in a window. To open DevTools, click the “Open DevTools” button. If the process sets to close, once you end your debugging session, DevTools will close automatically.

This in-built debugger option provides you with all the important features, developed by V8/Chromium team.

Read: What is the V8 JavaScript engine in Nodejs?

To debug a simple Node application located in app.js file,

var fs = require('fs'); fs.readFile('test.txt', 'utf8', function (err, data) { debugger; if (err) throw err; console.log(data); });

NODE INSPECTOR MANAGER(NiM) For Nodejs Application

NODE INSPECTOR MANAGER(NiM) For Nodejs Application
NODE INSPECTOR MANAGER(NiM) For Nodejs Application

Quick start

Install

$ npm install -g node-inspector

Start

$ node-debug app.js

Note: app.js is the name of the Node application JavaScript file.

Debug

The node-debug command will batch Node Inspector in your Chromium-based default browser.

How to use Node inspector with Chrome??

There are two options available to use Node inspector with Chrome:

Option 1: Open chrome://inspect in a Chromium-based browser(Chrome).

Click “Configure button” and select a target host and port that you need. Then select your Nodejs app from the list.

Option 2: Install the Chrome Extension NiM (Node Inspector Manager), Mostly try to go with the option 2.

Use NiM In Just 3 Easy Steps:

  1. Install
  2. Set hostname and port (use the default localhost and 9229).
  3. Click to Open DevTools

Features Of Node Inspector Manager(NiM)

The Blink DevTool debugger is a powerful debugger interface in JavaScript. Node inspector supports most of the features of Blink DevTool debugger, that includes:

  • Customize duration between v8 Inspector probes
  • Manual or automatic control of DevTools interface
  • Edit variables and object properties
  • Supports from Step over-step in-step out-resume
  • Network client requests inspection
  • Console output inspection
  • Open DevTools in a new tab or window
  • Make DevTools focused or inactive on start
  • Navigate in your source files and auto-save settings
  • Manage and monitor local and remote debugging sessions
  • Specify trigger conditions and set breakpoints
  • Inspect scopes, variables, object properties
  • CPU and HEAP profiling and disable/enable all breakpoints

Read: What are the special features of Nodejs?

Basic Troubleshooting Related To NiM

  1. My script runs faster than I expect to attach the debugger, what stuff is this actually?
  • The debug process must be started with –debug-brk, by this way the script is halted on the first line.

Note: node-debug comes with this option by default.

2. I got the UI in a ridiculous state, what should I do?

  • Simply refresh the page in a browser, when you are in doubt.

3. Can I debug the application remotely?

  • Yes, still you can debug remotely using Node Inspector that runs on the same machine, but your browser can be anywhere. And just make sure that port 8080 is accessible.

And if Node Inspector is not running on your remote machine, just launch Node Inspector with –no-inject which means some features are not supported such as profiling and consoling output inspection.

To debug a remote machine with your local Node inspector, follow the below-mentioned steps:

$ node-inspector --debug-host 192.168.0.2 --no-inject

then open the url http://127.0.0.1:8080/debug?port=5858

4. How do I specify files to hide?

  • Create a JSON-encoded array. You must quote the default characters when using a command-line option to hide.
$ node-inspector --hidden='["node_modules/framework"]'

Note that the array items are translated as regular expressions.

5. UI doesn’t load or doesn’t work and refresh didn’t help, what’s the solution?

  • Make sure that you have AdBlock disabled, and other content-blocking scripts, plugins, etc.

6. Why the Nodejs inspector takes a long time to start?

  • Try setting –no-preload to true. This option disables searching disk for *.js at the startup level. The code will be loaded into Node Inspector at runtime.

Advanced Use

While running node-debug, there must be an easy way to start your debugging process.

There Are Three Steps Needed To Get Started And Debugging:

  1. Start the Node inspector server
$ node-inspector

Leave the server to run on the background, so that it allows debugging multiple processes at the same server instance.

2. Enable debug mode in the Node process

You can enable debug mode using the below-mentioned command line,

$ node --debug your/node/program.js

Or, to pause the script in the first line itself,

$ node --debug-brk your/short/node/script.js

3. Load the debugger User-interface

Open http://127.0.0.1:8080/?port=5858 in the Chrome browser.

FINAL WORDS

Hope this blog helps you in a better way, and we would always like to hear from you. Contact us to know more in detail about the Nodejs web development process.

Ecommerce consultant

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store