0

I have 3 different MySQL database connections depending the environment (local, dev and live).

Using node-mysql, how do I serve the correct connection details or detect the environment being used?

Asa Carter
  • 2,207
  • 5
  • 32
  • 62

1 Answers1

2

The process.env.NODE_ENV variable is where the value is stored.

You can do something like:

if (process.env.NODE_ENV == 'production') 

OR this is built into the app.configure function

app.configure('development', function(){

});

app.configure('production', function(){

...
});

SETTING THE VARIABLE FROM COMMAND LINE

LINUX:

$ echo export NODE_ENV=production >> ~/.bash_profile
$ source ~/.bash_profile

WINDOWS:

set NODE_ENV=production
setx NODE_ENV production
ant_iw3r
  • 222
  • 1
  • 2
  • 10
  • Local environment is windows. Dev and production are Linux. – Asa Carter Jun 17 '14 at 19:19
  • edited answer. the linux example saves it to the bash profile so will exist after reboot. you could just "export NODE_ENV=production" on windows set temporarily sets it and setx is supposed to save it as an environmental variable. – ant_iw3r Jun 17 '14 at 19:28