mysqlnode.jsenvironment-variablesdev-to-production

i would like to auto detect the environment and set the appropriate variables


I have the same web application running on 2 different servers. It also runs on 2 different servers. Each of environment have its own database. The file config.json contains every database informations.

Developement environment: The app.js and database/db.js files, are calling a file getConf which retrieves config.json informations with preprod object.

Production: I update the retrieved object from preprod to prod.

Call:

// Pre-production
var config = require('./database/getConf').preprod 

// Production
var config = require('./database/getConf').prod 

I would like to do this automatically, which means, to update to production environment, I don't have to update any files. Just a copy paste from the dev but it detect automatically the environment and set the appropriate database.

I tried many modules like nconf, dotconf, and config but they all required to select the environment in the command line before launching the app.
But my 2 apps are running in two different IIS servers in my company and they're launched from IIS and not from the command line.

I hope doing just a copy paste of the hole project folder from thedev to the prod.


Solution

  • According to the documentation, you can find out pretty much every thing you need to know about the system with the module os.
    If you're looking for the CPU architecture : os.arch().
    If you're looking for which type of OS : os.type().

    Hope it can help you ^^.