NodeJS code debugging method

There are also many examples on the Internet, but I feel that they are all excellent big SBs who can't express themselves, so I will fill this vacancy.

foreword

Q: What should a good expression look like?

A: It should be so that a SB can understand it and start the debugging environment to complete the debugging.

text

Requirement: We need to debug a large section of node server code, we can't just print the log alone, so we also need to use breakpoint debugging to analyze the code that the code logic can't understand.

This time only for the windows environment, mac's own research.

Preparation tool: node-inspector, what the hell is node-inspector, it is the tool that can complete the debugging, we need to install this tool into the global environment of the system, that is, it can be accessed anywhere.

Step 1: Install this tool (command: npm install -g node-inspector);

Description: window+r starts and runs, enter cmd, do not need to enter any directory, enter the above command and press Enter, wait for the installation to complete as shown in the figure below, it means O cock K. Congratulations, you are amazing.

Step 2: Check the node-inspector version number (command: node-inspector -v);

Note: If you can see the version number, the installation is successful.

Step 3: Start the node-inspector debugging tool (command: node-inspector);

Description: In this step, an http link such as (http://127.0.0.1:8080/?port=5858) will appear, you can right-click the link to mark it, right-click, complete the copy, and throw it into the chrome browser Enter in the middle.

The debug window interface after startup is as follows:

Description: After completing the above three steps, the installation of node-inspector is completed and started successfully. Give yourself a quick applause, and then tell yourself that 666 turned 999, and you can also tell those SBs in your circle of friends who don't know how to show it off.

Step 4: Start our node service, and then we will start debugging our program. . . .

Description: Restart a window, window+r to start running, enter cmd, find the directory where your server file is located, copy the address, and use the command to enter this directory. For example, my project directory is as follows (my IDE is Hbuilder, right-click to open the directory where the file is located, copy the path, such as C:\Users\Administrator\git\DogNose\dogNose\js\server), and then enter this directory in the cmd command.

To execute the start command of our node service in the above path, please continue to look down.

Step 5: Start the node project server in debug mode.

Description: My server file is: service.js, so the startup command is (node ​​--debug service.js), and the startup is successful as shown below.

After completing the above operations, we go back to the browser window of the debugger and refresh it, and we will see the following results:

This shows the code in your server, you can debug the code on the server like you usually debug JS, ahaha, I am so happy, it is so easy..., quickly say: I am a Genius, ahahaha. . .

I try to break a point. First, I use the postman client to send a request as follows (of course, you can use a browser to send this request)

When finished, a debug window is displayed as follows

Well, that's it, you can just interrupt the point, play it, jump step by step, or choose to enter, enter and enter. . .

If you don't understand anymore, I can't help it, because who made you a fool. . . . 233333.. . . .

concluding remarks

88. If you want to call me a fool, please join our technical group: front-end/NODEJS/HTML5: 458633781 Welcome you. . . . .

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325563264&siteId=291194637