process.env.NODE_ENV仍在开发中,但仍显示出意外的行为 [英] process.env.NODE_ENV is in development still it shows unexpected behivour
问题描述
我正在开发环境中运行节点服务器,但是在我的服务器文件中它显示了意外的行为
I'm running my node server in development environment but in my server file it shows unexpected behaviour
我的剧本就像休假片一样
my script is as fallows:
var env = process.env.NODE_ENV;
console.log("------------------------------");
console.log("envenv",typeof env,env);
console.log("0",typeof env);
console.log("00",env);
console.log("2",env.toString()=='development');
console.log("3",""+env.toString()=='production');
console.log("2",env==='development');
console.log("3",env=="production");
console.log("------------------------------");
但它给出以下输出
but it gives following output
------------------------------
envenv string 'development'
0 string
00 'development'
2 false
3 false
2 false
3 false
------------------------------
当我尝试以下任何一项操作时,效果都很好
When I tried any of following it worked fine
var env = process.env.NODE_ENV.trim();
var env = process.env.NODE_ENV.toLowerCase();
var env = process.env.NODE_ENV.replace("","");
.............
或String类原型中的toString()以外的任何方法效果很好
or any method other then toString() which are in prototype of String class It worked fine
推荐答案
环境变量NODE_ENV包含多余的'
.设置环境变量时出了点问题.对于Windows系统使用
The environment variable NODE_ENV contains superfluous '
. Something went wrong when setting the environment variable. For windows system use
> SET NODE_ENV=development
代替
> SET NODE_ENV='development'
这应该可以解决问题.
要获取在命令行上打印的NODE_ENV的当前值,请使用
To get the current value of NODE_ENV printed on the command line use
> echo %NODE_ENV%
应该打印
> development
没有任何或"
这篇关于process.env.NODE_ENV仍在开发中,但仍显示出意外的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!