Nizar Blond Nizar Blond - 1 year ago 104
Node.js Question

express debug module not working

I'm on Windows trying to use the debug module

I installed express-generator

var debug = require('debug')('MyApp');
debug('log'); // I don't see this on console

I tried to debug the variable

console.log(debug); // I get function disabled() {}

How to enable it? shouldn't be enabled by default?


Output from debug functions created by the debug module are only displayed when you set the appropriate environment variable when starting your script. That is what lets you selectively enable debug output so that it's not an all or nothing method of displaying debug information. This is similar to how node.js core works for showing internal debug information on the console.

So in your example you would need to execute this at your shell prompt: DEBUG=MyApp node foo.js, where foo.js is your script containing var debug = require('debug')('MyApp');.

For Windows you'd need to do set DEBUG=MyApp on the command line, followed by node foo.js.