Asa Carter
Asa Carter

Reputation: 2225

Configure Different Node MySQL connections for different environments

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?

Upvotes: 0

Views: 397

Answers (1)

ant_iw3r
ant_iw3r

Reputation: 222

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

Upvotes: 2

Related Questions