表示debugging模块不工作
我在Windows上尝试使用debugging模块 https://www.npmjs.org/package/debug
我安装了快递发电机
var debug = require('debug')('MyApp'); debug('log'); // I don't see this on console
我试图debugging该variables
console.log(debug); // I get function disabled() {}
如何启用它? 不应该默认启用?
只有在启动脚本时设置适当的环境variables时,才会显示debug
模块创build的debuggingfunction的输出。 那是什么让你有select地启用debugging输出,所以它不是一个全部或没有显示debugging信息的方法。 这与node.js内核如何在控制台上显示内部debugging信息相似。
所以在你的例子中,你需要在shell提示符下执行: DEBUG=MyApp node foo.js
,其中foo.js
是你的包含var debug = require('debug')('MyApp');
脚本var debug = require('debug')('MyApp');
。
对于Windows,您需要在命令行中set DEBUG=MyApp
,接着是node foo.js
如果你想在你的js代码中设置它,
MYAPP-debug.js
#!/usr/bin/env node process.env['DEBUG'] = 'myapp:server'; var debug = require('debug')('myapp:server'); // ...
- 当有一个shebanged的可执行文件时(在你需要设置
node
打开.js
文件的窗口上),我发现它很有用。
Windows并不像Linux和其他人那样设置环境variables。
解决scheme是:
set DEBUG=my-application npm start
在Windows上设置DEBUG = *或您的configuration名称为debugging,例如myApp。 在所有的js文件中,每当我想debugging我configuration就像下面的语句。
var debug = require('debug')('MyApp');
require('debug') ('MyApp') ; / /这是非常imp。 您应该configuration一些名称进行debugging
而在Windows上执行
D:>set DEBUG=MyApp D:>node <your app file>.js D:> node foo.js
我试图解决这个问题,在我看来(至less在我的Windows 10机器上)做到这一点(至less从一个非Linux命令行;我使用WebStorm内置命令线)是包含'&'运算符。 所以写这样的东西:
set DEBUG=my-app & node index.js