Nodejs Debugging Tools-node-inspector

Source: Internet
Author: User

Nodejs More and more fire (really Huoshaohuoliao), its hot to the front-end development students pointed out a new way-also can do back-end development (or back-end development). This article is not to discuss how good nodejs, how to use, I believe that the students who want to find this kind of material has not satisfied to write a HelloWorld, the introductory tutorial has been unable to meet our love for Nodejs, we want to write more complex, more tall code. With the complexity of the system and the amount of code coming up, fixing a variety of bugs is the main work of our coder. The most common and effective way to locate bugs is to debug, because Nodejs is very, very young, and a lot of Ides don't support it very well, so let's talk about Nodejs's debugging methods. Cut the crap and get to the point (as if you've already said a lot).

I believe Nodejs debugging methods have a lot, in an article introduced too many in the way and not good, even after reading to the end still do not know with which, so I in this article only introduce a debugging tool--node-inspector, this debugging tool is based on NODEJS development.

Preparatory work

1. Nodejs Operating Environment

2, based on the Nodejs development program

3, Chrome browser (what to do with it, you will find out later)

We're just starting Nodejs's commissioning journey.

1, first of all we have to prepare NODEJS operating environment, without it we can nothing.

2, installation Node-inspector operating environment

Install command: NPM install-g node-inspector

Note: A, parameter-G installs the Node-inspector into the system environment variable, can be executed under any path, as far as possible to retain.

b, if it is a Linux or Unix system, you need to install with root permission

3. Start Node-inspector

Node-inspector startup will generate a service, mainly responsible for debugging tools and Nodejs program communication between the work, a bridge.

A, window: Execute node-inspector directly under any path

Do not close this window

B, Linux | | Unix:node-inspector & Node-inspcetor as a back-office service, so it is not afraid of misoperation, the window is turned off.

A process PID appears, indicating that Node-inspcetor has become a background process, can be CTRL + C to end the current task, node-inspcetor process remains.

If you want to stop can kill-9 PID kill Node-inspcetor process.

4. Open Chrome, enter address http://127.0.0.1:8080/debug?port=5858

I believe everyone saw something wrong, do you know what the reason is? Congratulations, you guessed it, our Nodejs program is not up yet, now it's time to go back and look at the changes in our Nodejs program.

5. Open Nodejs Debug mode

Node--debug app.js

Do you see any difference from the previous launch?

Yes, more than a line of information, debugger listening port is 5858, this port can be modified, please Baidu or Google.

6. Open Chrome again and refresh the page

The nasty mistake is gone, our chrome is connected to the Nodejs service via the Node-inspector service and displays the contents of the portal file for the Nodejs app.

In this case, we can track our Nodejs application just like the previous debug JS code. (How to use Chrome debugging is not here to say)

Summarize:

1, Node-inspector relies on the NODEJS operating environment.

2, during the commissioning of the Node-inspector service do not restart, just need to restart the Nodejs app after refreshing the Chrome page.

3, strictly speaking node-inspector is not a complete debugging tool, it needs a visual debugging interface to display all debugging information, Node-inspector is the debug interface and Nodejs between the bridge, is the debug interface can communicate with Nodejs.

Nodejs Debugging Tools-node-inspector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.