Many of us have probably used console.log
while debugging, and once we were done, removed it. This is not ideal because later on, either us or some colleagues might need to check out the same information, so it would have to be added (and perhaps removed or commented out) again.
Instead, we can employ the same technique used in Node core, Express, and other modules using a debug function that only outputs the arguments when an environment variable is set.
Try to run the preceding application (or any other Express application) using the following command:
$ NODE_DEBUG="http,net" node server.js
The Node core files make use of the NODE_DEBUG
environment variable to output debug information. In the preceding example, we have specified that we want to listen for the output that comes from two native modules: http
and net
. After you visit a page or two, the output should be similar to the following:
NET: 15418 listen2 0.0.0.0 7777 4 false NET: 15418 _listen2: create a handle NET...