Gitbash 没有正确设置环境变量
Gitbash is not setting environment variable correctly
我正在尝试在我的节点服务器中使用 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('Server started in port: ' + port + ' hostname: ' + domain);
没有向控制台打印任何内容。
我尝试解决这个问题
通过手动设置属性 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
- 会不会是别的东西?
提前致谢。
更多相关信息:
我的OS:Windows10
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.
我正在尝试在我的节点服务器中使用 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('Server started in port: ' + port + ' hostname: ' + domain);
没有向控制台打印任何内容。
我尝试解决这个问题
通过手动设置属性 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
- 会不会是别的东西?
提前致谢。
更多相关信息:
我的OS:Windows10
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.