Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NODE_ENV=development set in .bash_profile but undefined when using it in code

My ~/.bash_profile content:

export MONGO_PATH=/usr/local/mongodb
export NODE_ENV=development
export PATH=$PATH:$MONGO_PATH/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"

# {{{
# Node Completion - Auto-generated, do not touch.
shopt -s progcomp
for f in $(command ls ~/.node-completion); do
  f="$HOME/.node-completion/$f"
  test -f "$f" && . "$f"
done
# }}}

However in my app.js code my process.env.NODE_ENV is undefined. I've searched for my issue but only find how to set it and I seemed to have followed "how to" correctly. Am I missing something?

like image 580
ChadH Avatar asked Aug 23 '15 03:08

ChadH


2 Answers

Keep in mind you'll also need to reload the .bash_profile after editing it:

source ~/.bash_profile

or, alternatively: . ~/.bash_profile

like image 115
sugarcane Avatar answered Nov 08 '22 16:11

sugarcane


I think that something within your ~/.bashrc could be overwriting NODE_ENV var, but it doesn't really matter, because if you want the default behaviour of your app.js be to run as 'development' by default, you just should have something like:

var run_mode = process.env.NODE_ENV || 'development';

if(run_mode === 'development'){
   // development mode
} 
like image 21
Rubén Marrero Avatar answered Nov 08 '22 18:11

Rubén Marrero