Debugging messages

You can generate quite a detailed trace of what Express does by running Notes this way:

$ DEBUG=express:* npm start  

This is pretty useful if you want to debug Express. But, we can use this in our own code as well. It is similar to inserting console.log statements, but without having to remember to comment out the debugging code.

It is very simple to enable debugging in a module:

const debug = require('debug')('module-name'); 
.. 
debug('some message'); 
.. 
debug(`got file ${fileName}`); 

Get Node.js Web Development - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.