Can't access the NODE_ENV environment variable properly, is this a bug with node.js?

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?

Looks like your environment variable has some funny characters, possibly due to the way it's being set outside of Node.js. You could try this:

if (process.env.NODE_ENV.replace(/\W/g, '') == 'development') {
  console.log('ok');
}