express debug module not working

In case you want to set it in your js code,

myapp-debug.js

#!/usr/bin/env node

process.env['DEBUG'] = 'myapp:server';
var debug = require('debug')('myapp:server');

// ...
  • I find it useful when there's a single shebanged executable file (on windows you'l need to set node to open .js files)

On windows set DEBUG=* or your configured name for debug e.g. myApp. In all js files whenever I want debug I configured just like following statement.

var debug = require('debug')('MyApp'); 

require('debug')('MyApp'); //This is very imp. You should configured some name for debug

while executing on windows

D:>set DEBUG=MyApp

D:>node <your app file>.js 

D:> node foo.js

I was also faces the same issue. Finally i get the solution that In windows

set DEBUG=* & node index.js

above command has to work. But in my this is not working on VS code terminal. But if is you write this command in scripts section of your package.json then it will work.

"start": "set DEBUG=app & node app.js"

Now you just need to write

npm start

on terminal and there you go


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.