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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With