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