我正在尝试在我的 Node 服务器中使用npm install debug
。
var debugModule = require('debug');
var debugMainApp = debugModule('debugMainApp')
const express = require('express');
const app = express();
const port ='3000';
const domain = 'localhost';
app.listen(port,domain,()=>{
debugMainApp('Server started in port: ' + port + ' hostname: ' + domain);
});
debugMainApp('服务器在端口启动:' + port + ' 主机名:' + 域);
没有向控制台打印任何内容。
我尝试解决此问题
通过手动设置属性 debugMain.enabled = true
debugMainApp('Server started in port: ' + port + ' hostname: ' + domain);
将以下内容打印到控制台:
mainApp Server started in port: 3000 hostname: localhost +0ms
据我了解,当设置与字符串 debugModule('this_String')
匹配的环境变量时,应自动设置此 debugMain.enabled
属性。
这是我设置环境变量并启动服务器的方法
$ DEBUG=debugMainApp & node server.js
但似乎后者没有正确设置环境变量。
问题
- 如果你认为我的环境变量理论是正确的。使用 GitBash 命令行设置环境变量的正确方法是什么?例如
$ DEBUG=mainApp & node server.js
- 会不会是别的什么?
提前致谢。
更多相关信息:
我的操作系统:Windows 10
GitBash 版本:2.13.0.windows.1
NodeJS 版本:6.10.3
最佳答案
& 将指示 bash 在后台启动进程。
正确的语法是:
DEBUG=mainApp node server.js
查看更多信息“Why is setting a variable before a command legal in bash?”
A simple command is a sequence of optional variable assignments followed by blank-separated words and redirections, and terminated by a control operator.
关于node.js - Gitbash 未正确设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48873660/