我想弄清楚我的会话有什么问题(使用express-session),我发现它使用了debug module。但是,我似乎无法启用调试消息。它说,调试需要通过DEBUG
环境变量启用,但我似乎无法让它运行。
自述文件中的教程有这样的图片:
在Windows下我得到" DEBUG
不是命令行的命令"。
所以我尝试使用:
显式设置环境变量 process.env.DEBUG = "*";
但仍然没有。
我做错了什么?
答案 0 :(得分:11)
作为评论中建议的Traveling Tech Guy,在Windows命令提示符中,正确的语法是:
set DEBUG=* & npm start
显然,您可以使用启动Node.js应用程序所需的任何命令替换npm start
。请务必使用set
命令,不要忘记该命令与启动Node.js应用程序之间的&
!
答案 1 :(得分:5)
如果您习惯使用Powershell,建议您在 package.json 中使用此设置,然后只需运行npm start
,这样就不必每次都键入所有内容。 / p>
"scripts": {
"start": "@powershell $env:DEBUG='*,-express:router*' ; node app.js"
},
答案 2 :(得分:3)
首先,您需要使用
安装调试模块 "npm install debug --save"
您将看到以下通道已添加到您的package.json(其中所有npm模块已向您的项目收费)
然后您需要添加此项以将模块导入到您要在其中运行调试的文件
var debug = require('debug')('name_to_call');
现在我们只需要输入我们想写的消息,例如hello
var debug = require('debug')('name_to_call');
debug('Hello');
(尝试将上面的代码直接粘贴到文件中)
现在我们只需要使用
来节点化我们的服务器 "DEBUG=name_to_call node server.js"
答案 3 :(得分:3)
在节点应用程序中使用npm安装调试包
npm install debug
打开PowerShell然后
$Env:DEBUG="name_to_call"
node path_to_js_to_execute.js
在你的pgm里面
var debug = require('debug')('name_to_call');
答案 4 :(得分:1)
在Babun一个Windows shell中,我运行,
NPM
npm install debug --save
babun
DEBUG=http node app
app.js
var app = express();
var debug = require('debug')('http');
var http = require('http').Server(app);
var server = http.listen(app.get('port'), function() {
debug('listening on port ' + server.address().port);
});
对我来说就像一个魅力。