Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Load configuration files for Node.Js Servers
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
Jakefile.js
README.md
index.js
package.json

README.md

server-config

One of the fundamental problems of software development is keeping configuration information for different environments. Most organizations distinguish environments such as DEV, QA, Staging, and Production.

The configuration approach promoted by this little utility makes it uncesseary to keep an elaborate build process supporting these different enviroments. Using this utility, configuration information can be stored in embedded defaults that can be overriden using a configuration file and environment variables.

Example

var path = require('path'),
    loadConfig = require('server-config'),
    ec2instance = loadConfig.ec2instance,
    embedded = {
      "httpPort": 80,
      "httpsPort": 443,
      "seaPort": 9090
    },
    host = '~/.defaults.json#myapp',
    env = {
        mongdb: process.env["MONGODB"],
        seaPort: process.env["SEA_PORT"]
    },
    ec2 = {
        "public-hostname":ec2instance("meta-data/public-hostname"),
        "hostname":ec2instance("meta-data/hostname")
    };

    loadConfig(embedded, host, env, ec2, function(err, config) {
        if (err) {
          throw err();
        }
    });

Let's further assume the host file contains:

{
  "myapp": {
    "httpPort": 3000,
    "mongodb": "mongodb://localhost/testbase",
    "welcomeMsg: "Hellow World!"
  }
}

Lastly, let's assume that there is one evnironment variable defined:

export SEA_PORT=2000

If all this is the case, the resulting config information returned by the call above would be:

{
  "httpPort": 3000,
  "httpsPort": 443,
  "welcomeMsg: "Hellow World!",
  "seaPort": 2000
}
Something went wrong with that request. Please try again.