About debugging
When we only focus on the front end, we are accustomed 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
Installing 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, the startup is successful.
Start the debug mode of nodejs
Reopen a terminal, and then start the debug debugging function provided by nodejs
C:\Users\Administrator\Desktop>node --debug-brk event.js Debugger listening on port 5858
- -debug-brk means to use debug mode to start event.js and 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 Script Home!
nodejs connectionmongodbDatabase implementation of addition, deletion, modification and query
Nodejs Detailed explanation and explanation of building a simple web server Example
window automatically runs nodejs application in the background through vbs+bat
NodeJs reads JSONNotes when formatting files
nodejs WeChat public account payment development
nodeJs memory Detailed explanation of leakage problem
Advantages of NodeJs and programs suitable for development
Use nodejs to build staticSimple method of file server on windows
Nodejs captures html page content (recommended)
Using nodejs implementation principles and building servers (dynamic)
nodejs how to get timestamp and time difference
NodeJS combined with HTML5 to drag and drop multiple files Implementation method of uploading to the server
The above is the detailed content of Detailed introduction to debugging methods of NodeJs. For more information, please follow other related articles on the PHP Chinese website!