3 minute Dry Goods learn to debug Nodejs code with Node-inspector

Source: Internet
Author: User

Debugging Nodejs code with Node-inspector

Any complete language technology stack is not without robust debugging tools, for the Nodejs platform is the same, the author studies several ways to debug Nodejs code, through comparison, or feel Node-inspector debugging method is more convenient, and the debugging of the front-end JavaScript code has a consistent experience, not only robust, but also convenient. After the installation completes Nodejs the following instruction can complete the Node-inspector installation.

>NPM install-g Node-inspector

Node-inspector run the following command to start Node-inspector after the installation is complete.

Edit the Nodejs source code to enter the following code and name it test.js

    varDuck ={ducksinging:function() {Console.log (' Quack ' );    }    }; varChicken ={ducksinging:function() {Console.log (' Quack ' );    }    }; varChoir = [];//Choir    varJoinchoir =function(animal) {if(Animal &&typeofanimal.ducksinging = = = ' function ') {Choir.push (animal); Console.log (' Congratulations to join the choir ' ); Console.log (' Choir already has a membership number: ' +choir.length);    }    };     Joinchoir (duck); Joinchoir (chicken);

Execute the following command to the path where the Test.js file is located:

>node--debug-brk Test.js

Open Chrome to enter the address of the Node-inspector prompt, You will find that the breakpoint has been hit in the first line of the Test.js code, so far, we can step into the execution or full speed execution of our Nodejs code, such as, of course, we can also set a breakpoint, and then node--debug test.js start the debugging Nodejs code, and to Debug.

Summarize

This article summarizes the complete steps of using Node-inspector to debug Nodejs code, with detailed illustrations of the relevant steps, we hope to help you. It is worth mentioning that the use of Node-inspector debugging Nodejs code There is a need to note that when we debug the cluster or multi-process Nodejs code, we can only debug the open debug port of the process, if you need to debug other sub-processes, You need to find the listening port of the child process and mount the browser to the appropriate port to complete the debugging work.

3 minute Dry Goods learn to debug Nodejs code with 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.