Node.js Inspector

10 Jul, 2020
What is inspector in Node.js?Inspector in node.js is a debugging interface for node.js application that is contained in the app.js file and used blink developer tools. It works almost similar to chrome developer tools. It can support almost all the feature that a debugger generally have such as navigating to source files, setting breakpoints, CPU and heap profiling, network client requests inspection, console output inspections, and many other features.
How to install?It can be installed by running the following command in the command line after installing npm (node package manager).
$ npm install -g node-inspector
Here in the command, -g flag corresponds to global installation of the inspector. After installing if you run command node-inspector, we get an output like this:
After successful installation
In the above figure, it displays an URL for debugging purpose. So, when we point our browser to http://127.0.0.1:8080/?port=5858, we get a GUI for debugging. Sometimes, port 8080 may not be available on the computer then we will get an error. We can change the port (in this case port 5555) on which node-inspector is running by using the following command:
$ node-inspector --web-port=5555
How to start using it?It can be started using following command in command line:
$ node-debug app.js
where app.js is the name of the main JavaScript application file. Available configuration options can be seen here.
While debugging app.js file
The node-debug command will load Node Inspector in the default browser.Note: Node Inspector works in Chrome and Opera only.
Advanced Use: While running node-debug is an easy way to start your debugging session, sometimes we need to tweak the default setup. Then we need to follow three steps given below
Start the node-inspector server: This can be done by running command:$ node-inspectorThe server can be left running in the background, it is possible to debug multiple processes using the same server instance.Enable debug mode in the node process: You can either start Node with a debug flag like:$ node --debug your/node/program.jsor, to pause your script on the first line:$ node --debug-brk your/short/node/script.jsOr one can enable debugging on a node that is already running by sending it a signal:Get the PID of the node process using your favorite method. pgrep or ps -ef are good.$ pgrep -l node2345 node your/node/server.jsSend it the USR1 signal$ kill -s USR1 2345Load the debugger UI: Open http://127.0.0.1:8080/?port=5858 or the produced URL in the Chrome browser.
Start the node-inspector server: This can be done by running command:$ node-inspectorThe server can be left running in the background, it is possible to debug multiple processes using the same server instance.
$ node-inspector
The server can be left running in the background, it is possible to debug multiple processes using the same server instance.
Enable debug mode in the node process: You can either start Node with a debug flag like:$ node --debug your/node/program.jsor, to pause your script on the first line:$ node --debug-brk your/short/node/script.jsOr one can enable debugging on a node that is already running by sending it a signal:Get the PID of the node process using your favorite method. pgrep or ps -ef are good.$ pgrep -l node2345 node your/node/server.jsSend it the USR1 signal$ kill -s USR1 2345
$ node --debug your/node/program.js
or, to pause your script on the first line:
$ node --debug-brk your/short/node/script.js
Or one can enable debugging on a node that is already running by sending it a signal:
Get the PID of the node process using your favorite method. pgrep or ps -ef are good.$ pgrep -l node2345 node your/node/server.jsSend it the USR1 signal$ kill -s USR1 2345
Get the PID of the node process using your favorite method. pgrep or ps -ef are good.$ pgrep -l node2345 node your/node/server.js
$ pgrep -l node
2345 node your/node/server.js
Send it the USR1 signal$ kill -s USR1 2345
Send it the USR1 signal
$ kill -s USR1 2345
Load the debugger UI: Open http://127.0.0.1:8080/?port=5858 or the produced URL in the Chrome browser.
For more details we can refer to the official documentation.
Node.js-Basics
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JWT Authentication with Node.js
Installation of Node.js on Windows
Difference between dependencies, devDependencies and peerDependencies
Mongoose Populate() Method
Mongoose find() Function
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React