Permalink
Browse files

add example

  • Loading branch information...
1 parent 77cc5cc commit ebf303a664191e52e49cc2409294bef58c571600 @rjyo committed Jun 6, 2011
Showing with 49 additions and 16 deletions.
  1. +15 −15 Readme.md
  2. +15 −0 examples/app.yaml
  3. +18 −0 examples/run.js
  4. +1 −1 lib/yaml-config.js
View
@@ -12,21 +12,21 @@ Manage your configuration based on NODE_ENV, all configuration defined with yaml
In the setting file at `confing/app.yaml`
```yaml
- default:
- redis:
- port: 6379 # redis server port
- host: '127.0.0.1' # redis host
- password: '' # to use with AUTH
- db: 1 # the test db
- options: {}
- test:
- redis:
- db: 12
- production:
- redis:
- db: 0
- new_prop:
- hello: 'world'
+default:
+ redis:
+ port: 6379 # redis server port
+ host: '127.0.0.1' # redis host
+ password: '' # to use with AUTH
+ db: 1 # the test db
+ options: {}
+test:
+ redis:
+ db: 12
+production:
+ redis:
+ db: 0
+ new_prop:
+ hello: 'world'
```
In your source code
View
@@ -0,0 +1,15 @@
+default:
+ redis:
+ port: 6379 # redis server port
+ host: '127.0.0.1' # redis host
+ password: '' # to use with AUTH
+ db: 1 # the test db
+ options: {}
+test:
+ redis:
+ db: 12
+production:
+ redis:
+ db: 0
+ new_prop:
+ hello: 'world'
View
@@ -0,0 +1,18 @@
+// $ cd examples; node run.js
+var config = require('..');
+var env = process.env.NODE_ENV || 'development';
+
+var settings = config.readConfig('app.yaml'); // path from your app root without slash
+console.log('env = %s', env);
+console.log(settings); // if NODE_ENV is development, prints 1
+
+env = 'test'
+settings = config.readConfig('app.yaml', env);
+console.log('env = %s', env);
+console.log(settings);
+
+env = 'production'
+settings = config.readConfig('app.yaml', env);
+console.log('env = %s', env);
+console.log(settings);
+
View
@@ -1,7 +1,7 @@
var yaml = require('yaml')
, fs = require('fs')
, Log = require('log')
- , log = new Log(Log.DEBUG);
+ , log = new Log(Log.INFO);
var extend = function(dest, from) {
var props = Object.getOwnPropertyNames(from);

0 comments on commit ebf303a

Please sign in to comment.