pregmatch pregmatch - 2 years ago 97
Node.js Question

How to use nodejs debug module but only for some directory?

I have my app started with:

NODE_ENV=development DEBUG=* node-supervisor server

but that will debug everything (everything from node_modules)

How can I exclude node_modules from debug or how can i debug only one directory?

I am using:

Answer Source

You can't debug one directory, but you can make sure that only your own code's debug messages are shown:

// your code
var debug = require('debug')('my-code');
debug('hello world');

// to only show debug messages from your own code:
DEBUG=my-code node-supervisor server

You can even create a subdivision to debug only parts of your code:

// file1.js
var debug = require('debug')('my-code:file1');

// file2.js
var debug = require('debug')('my-code:file2');

If you only want to see debug messages from file1.js:

DEBUG=my-code:file1 ...

Or show all debug messages from your code by using a wildcard:

DEBUG=my-code:* ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download