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 the asynchronous capability is very good.
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.
NodeJS and html5. how to drag multiple files to the server
The above is a detailed description of the NodeJs debugging method. For more information, see other related articles in the first PHP community!