Node Debug如何在代码中设置DEBUG

时间:2015-04-02 07:36:37

标签: node.js

我想在我的应用中使用调试模块 而不是console.log或类似的 但没有运行我的应用程序:

DEBUG=app node server

所以我尝试过:

if (app.get('env') === 'development') {
    process.env.DEBUG = 'app';
}

但它没有用。

有没有办法在代码中设置DEBUG模式?

更新

感谢@thefourtheye(见评论)

if (process.env.NODE_ENV === 'development') {
    process.env.DEBUG = 'app';
}
var debug = require('debug')('app');

更好

if (process.env.NODE_ENV === 'development') {
    process.env.DEBUG = 'app:*';
}
var debug = require('debug'),
    info = debug('app:info'),
    error = debug('app:error');

0 个答案:

没有答案
相关问题