目前console.log
,我的模块中有很多东西。其中许多是调试消息,如果要调试应用程序,则只需要查看它们。
例如,我想在启动应用程序时使用参数启用调试node myApp.js -d
。此外,console.log
如果调试处于活动状态,则我的模块仅应调用if。
Node的最佳实践是什么?
查找npm debug。我相信这就是您想要的。
要安装调试:
npm install debug --save
示例代码:
var debug = require('debug')('your module');
debug('msg', 'more details');
要开始调试所有应用程序,请运行以下命令:
DEBUG=* node myApp.js
要在您的应用程序上仅调试几个模块:
DEBUG=first,second node myApp.js
无需调试即可正常运行您的应用
node myApp.js
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句