I'm going to play node recently.
As we all know, in the front-end, debugging code has a good natural tools-browser! Chrome, in particular, makes the Jser a duck's play. But to node, the situation is not the same, JS code is no longer running in a simple browser, but directly running in the operating system, turned into a class citizen. From then on, this node JS and browser is no longer same boat, but the cowboy and Weaver, in the middle of a big Milky Way!
A few years ago a colleague used Nodejs to write a mail service reverse proxy, doing some distribution and minor processing. The number of users is not small, but often crash. Fortunately, node event mechanism is relatively perfect, down can be restarted in time, so the effect is quite good. At that time colleague debugging code mainly with Node-webkit, I also tried, very good! As if debugging in the browser, and can read and write files, do the programming language of the citizens can do things, very open to life!
Recently saw colleagues using Node-inspector debugging, familiar interface, and Node-webkit almost. But I think since there is a node-webkit, and a node-inspector, there must be a different place! Holding such curiosity, I began to toss Node-inspector.
Because it is working with a Mac, there is a ready node on the computer. Only need homebrew install Node-inspector, PA ... It's ready in a few moments. NODE-INSPECTOR-V, PA! v.0.12.4. Then there is the routine Hello world!, as follows:
1 varHTTP = require (' http ');2 varPort = 8080;3 varFS = require (' FS ');4 5Http.createserver (function(req, res) {6Res.writehead, {' Content-type ': ' Text/plain '});7Res.end (' Hello world\n ');8}). Listen (port, ' 127.0.0.1 ');9 Ten OneConsole.log (' Server running at http://127.0.0.1: ' + port + '/');
Feel very good, follow the instructions, first execute
$ node-inspector
Re-execute
$ node--debug-brk server.js
Follow the instructions above to execute node-inspector, open in the browser
http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858
Perform debugging. Copy and paste, pops! good! The debugging interface came out and it went well.
Excitement, involuntarily refreshed several times the browser, a flash ... A flash of ... A flash, after all, is not flash out, the page blank!
Very sad! I think it may be that the port is occupied by other programs, with the TCP command to see, found no program occupied AH. Open the Browser development tool, found a few errors, is with runtime ... Related issues, so the wrong copy mercilessly Google. Sure enough, there are already peers in the online discussion of this error!
Some of it is to disable some of the browser extensions.
There are some control parameters (too complex and do not know how) to start the chrome.
Some say node and Node-inspector's version is wrong.
What's more, the homebrew installation may be different from the NPM installation ...
I tried each one, without a success. Copy the Node-inspector on your colleague's computer, too. Then I was exhausted and put on hold.
Without such a good debugging tool, I am not allowed to allow this to happen!
So this evening I began to toss again. After restarting a few times, it is OK to open the browser for the first time after each reboot, but it will not work in the future. This time, I am awake! So I thought about changing the port, there may be a conflict with the node-inspector 8080. So I changed it to the following:
var http = require (' http '); var port = 8000; var fs = require (' FS '); http.createserver(function (req, res) { Res.writehead ( {' Content-type ': ' Text/plain '}); Res.end (' Hello world\n '127.0.0.1 '); Console.log (' Server running at http://127.0.0.1: ' + Port + '/');
Stop sever restart and refresh the browser. The first time is as successful as the forward, refreshed, nice! It's finally done! Temporarily not clear deep-seated reasons, late at night to study again! Record this exciting moment here!
Nodejs Debugging Tools Node-inspector Getting Started essays