I'm accessing the NODE_ENV environment variable to turn on some debug features in a node.js server. It used to work like a charm, but now I'm facing some very weird stuff. Here's what I'm doing:
// check if the env var is OK
console.log(process.env.NODE_ENV);
// WTF???
if (process.env.NODE_ENV == "development") {
console.log("ok");
}
else {
console.log("nope");
}
// sanity check
var str = "development";
if (str == "development") {
console.log("ok");
}
else {
console.log("nope");
}
And here is what I get:
development
nope
ok
How is that possible? Am I facing a bug in node.js? If not, what am I doing wrong?
EDIT
Following Pointy's comment below, here's what I get if I change my initial log to console.log("[" + process.env.NODE_ENV + "]");
:
]development
nope
ok
So, a known issue maybe?
console.log("[" + process.env.NODE_ENV + "]");
to see if there are trailing spaces maybeNODE_ENV=development node /tmp/p.js
it works correctly.