Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

process.env.NODE_ENV not matching 'development' no matter what

Just migrated on the latest Express, and stuck in something completely simple. So, how is it possible, that this distilled example:

var env = process.env.NODE_ENV || 'development';
console.log(env);
if ('development' == env) {
    console.log('im here');    
}
else {
    console.log('nah');    
    console.log(env);
}

with this server file runned as SET NODE_ENV=development & node server.js

gives output:

development
nah
development

instead of

development
im here

By the way, if I'll just manually set var env = 'development' then it work as it should be.

express 4.11.2, node 0.12.0, win8 x64.

like image 896
Max Yari Avatar asked Feb 22 '15 15:02

Max Yari


2 Answers

I got same problem on windows mode. I'm not sure on linux. This problem caused by spaces between word "development" with "&" character. You can fix by remove spaces on your command. Example:SET NODE_ENV=development& node server.js

like image 70
The-x Laws Avatar answered Oct 04 '22 22:10

The-x Laws


Your code looks fine, therefore the reason the equality test must be failing is because the strings aren't equal. Make sure you don't have any extra characters like spaces in your environment variable development string.

like image 31
Jack Guy Avatar answered Oct 04 '22 22:10

Jack Guy