Parse the debugging method of NodeJs and parse the debugging method of nodejs
About debugging
When we focus only on the front-end, we use F12, which brings us a sense of security and comfort.
But when we use NodeJs for background development, I have a nightmare.
But don't worry about Thailand. It is inconvenient to debug NodeJs! This is for sure.
But fortunately, we have # node-inspector # To help us solve some debugging problems, but it is still a little powerless for NodeJs with strong asynchronous capabilities.
Node-inspector
Install node-inspector
We still use npm to install node-inspector globally.
npm install -g node-inspector
Test code
// Event. jsvar events = require ('events'); var util = require ('util'); function tianxi.pdf (name) {this. name = name; events. eventEmitter. call (this);} util. inherits (Restaurant, events. eventEmitter); // defines the role var restaurant = new tianxi.pdf ('yijian ');
This is the code to debug.
Start node-inspector
Start node-inspector first
C:\Users\Administrator>node-inspectorNode Inspector v0.12.8Visit http://127.0.0.1:8080/?port=5858 to start debugging.
All right, start successfully.
Start the debug mode of nodejs
Restart a terminal and start the debug debugging function provided by nodejs.
C:\Users\Administrator\Desktop>node --debug-brk event.jsDebugger listening on port 5858
-- Debug-brk means to start event. js in debug mode and breakpoint on the first line.
View results
In this way, two programs communicate through socket. We can debug NodeJs in our Google Developer Tools.
The following debugging process is similar to that of Js debugging.
The above is all the content of this article. I hope this article will help you in your study or work. I also hope to provide more support to the customer's home!