About debugging
When we only focus on the front end, we are used to F12, which will bring us a sense of security and comfort.
But when we use NodeJs to develop the backend, I think the nightmare is coming.
But don’t worry, debugging NodeJs is very inconvenient! Definitely.
But fortunately, we have ## node-inspector ## to help us solve part of the debugging problems, but it is still a bit inadequate for NodeJs, which has strong asynchronous capabilities.
node-inspector
Install node-inspector
Still install node-inspector globally through npm
npm install -g node-inspector
Test code
//event.js var events = require('events'); var util = require('util'); function tianxiasan(name){ this.name = name; events.EventEmitter.call(this); } util.inherits(Restaurant, events.EventEmitter); //定义角色 var restaurant = new tianxiasan('奕剑');
This is the code we want to debug
Start node-inspector
Start node-inspector first
C:\Users\Administrator>node-inspector Node Inspector v0.12.8 Visit http://127.0.0.1:8080/?port=5858 to start debugging.
Okay , started successfully.
Start the debug mode of nodejs
Reopen a terminal, and then start the debug function provided by nodejs
C:\Users\Administrator\Desktop>node --debug-brk event.js Debugger listening on port 5858
--debug-brk means to use the debug mode to start the event .js and put a breakpoint on the first line.
View the effect
In this way, the two programs communicate through socket. We can debug NodeJs in the Google Developer Tools in our properties.
What a familiar interface, the debugging process below is similar to Js debugging.
The above is the entire content of this article. I hope that the content of this article can bring some help to everyone's study or work. I also hope to support the PHP Chinese website!
For more articles on scope issues in Nodejs, please pay attention to the PHP Chinese website!