I am on Ubuntu 12.04 and I am only learning environment variables. I am trying to read a user variable from my application, but it always displays as undefined . Here is the code for my test application:
// app.js console.log('Value: ' + process.env.NODE_ENV);
If I execute the following commands, you will see that the variable has a value:
$ NODE_ENV=production $ echo $NODE_ENV production
I can echo $NODE_ENV all day and it will continue to show me "production", but when I execute process.env.NODE_ENV in my Node application, it always displays "undefined".
$ node app.js Value: undefined
Here's the weird part, though, if I show another environment variable that, as I know, already exists, say process.env.PATH , then it will work.
$ node app.js Value: /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Another oddity is that the printenv list command does not contain my custom variable NODE_ENV despite the fact that echo $NODE_ENV shows me the correct value. printenv NODE_ENV does not show anything, but printenv PATH shows the correct value in the same way as when I accessed PATH in my node application.
Chev
source share