Skip to content

Commit

Permalink
Merge branch 'patch-1' of https://github.com/ramitos/konphyg
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte committed Oct 15, 2012
2 parents 805386a + baf9009 commit b2696a0
Showing 1 changed file with 35 additions and 45 deletions.
80 changes: 35 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ These should be JSON files, terminated by ".json".

This example loads and parses the ../config/redis.json file:

// Initialize konphyg with the base config dir
var config = require('konphyg')(__dirname + '../config');
```js
// Initialize konphyg with the base config dir
var config = require('konphyg')(__dirname + '../config');

// Read the "redis" domain
var redisConfig = config('redis');
// Read the "redis" domain
var redisConfig = config('redis');
```

Loading all configurations:
```js
// Initialize konphyg with the base config dir
var konphyg = require('konphyg')(__dirname + '../config');

// Read the "redis" domain
var config = konphyg.all();
```

## Environment-specific files and cascading

Expand All @@ -34,62 +45,41 @@ What happens here is that the settings in the base configuration are merged with

For instance let's say you have this `redis.json` file:

{
"host": "redis.acme.com"
, "port": "6379"
}
```json
{
"host": "redis.acme.com"
, "port": "6379"
}
```

and that you have this `redis.development.json` file:

{
"host": "127.0.0.1"
}
```json
{
"host": "127.0.0.1"
}
```

The resulting configuration for the development environment will be the merge of the 2:

{
"host": "127.0.0.1"
, "port": "6379"
}

```json
{
"host": "127.0.0.1"
, "port": "6379"
}
```

This also works with attributes nested at any level.

# Explicitly Require Environment File(s)

Optional feature. At require time or per configuration fetch specify if an environment file is mandatory. If not found then an Error will be thrown. Normal behavior is to simply ignore the
non-existence of an environment specific file.

At require time:

// Initialize konphyg with the base config dir (require environment files)
var config = require('konphyg', true)(__dirname + '../config');

Or at configure time:

// Normal require
// ...

// Read the "redis" domain (environment file must exist)
var redisConfig = config('redis', true);

Also, over-riding require time mandate at configure time:

// Initialize konphyg with the base config dir (require environment files)
var config = require('konphyg', true)(__dirname + '../config');

// Read the "redis" domain (over-ride, environment file doesn't need to exist)
var redisConfig = config('redis', false);


## NODE_ENV defaults

If not present, the chosen environment is 'development'.

If you want to launch a node process using the 'production' environment you should then do something like:


$ NODE_ENV=production node app.js
```bash
NODE_ENV=production node app.js
```

# Resources

Expand Down

0 comments on commit b2696a0

Please sign in to comment.