What Is Node Inspector Manager 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.

Read More: What is the V8 JavaScript engine in Nodejs? 

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.

Launching Headless Ecommerce in Node.js, Powered by Microservices. Node Inspector Manager

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 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 Node Inspection NiM In Just 3 Easy Steps:

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

Node Inspector Manager Nodejs Features

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 More: What are the special features of Nodejs?

Basic Troubleshooting Related To Inspector Nodejs NiM

  1. My script runs faster than I expect to attach the debugger

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.

  1. I got the UI in a ridiculous state

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

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

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

  1. UI doesn’t load or doesn’t work and refresh didn’t help 

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

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

Read More: Golang vs Nodejs: Which Suits Best For Backend Development?

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.

  1. Enable debug mode in 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
  1. 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.

Are You Prepared to Switch to a Headless Solution? node inspection

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *