kristjanmik/apis — pull request #41 by arnorhs (2013-05-04 05:16:45+00:00)
Title: Adding configuration environments

Ok, so I've added some basic form of configuration environment support.

The thing is that I think it will change a bit the server deployment, so I'm not sure if there are better ways to do this.

###Why?

I was going to add email support in the app, but realized that at that point we might need to start putting in passwords etc, which would always be different depending on each user.

We'll also be able to override config for development (like whether or not to log errors to log file, email or whatever) specifically w/o it affecting the production config.

This will make it easier for people to run their server setup on a different port etc, w/o manually changing the port in a few places.

###First, a bit bout the setup:

Environment specific config files (dev, production, testing? etc) are stored in:

config/xxx.config.json

Global defaults that will always be included are in `config/default.json`

If you want to start the server using a specific configuration, let's say it's called "staging", you'd start the app like this:

NODE_ENV=staging node server.js

So the current server config always depends on which environment you are starting in.

I think this is pretty much the standard way to configure environment specific instances.

I added `config/*.config.json` to `.gitignore` so you can change `dev.config.json` to your liking w/o accidentally checking it into source control.

###Defaults

This setup defaults to the `dev` environment, and I already created that file, so for running the app normally nothing will change.

You can also clear out the `dev.config.json` file (as in so it's just `{}`) and then it will just use the defaults, since it's all inherited.

###The catch

RIght now, as I understand it, we deploy by pulling in the master from github. In order for this to work in production, we'd need to do this on the server after pulling in the changes:

- Create a copy of `config/dev.config.js.example` to `config/production.config.js` file in the config directory on the server.
- always start the server using `NODE_ENV=production forever server.js` (or whatever the command is that we use to start in production.

*Any thoughts?*