From c88c038b06f559885daea442882a07a63c7d01ca Mon Sep 17 00:00:00 2001 From: rjz Date: Sat, 16 Aug 2014 07:12:03 -0700 Subject: [PATCH] Uses confilter for config --- app.js | 2 +- config.json | 4 ---- config/config.json | 4 ++++ config/config.test.json | 4 ++++ config/index.js | 22 ++++++++++++++++++++++ package.json | 3 ++- 6 files changed, 33 insertions(+), 6 deletions(-) delete mode 100644 config.json create mode 100644 config/config.json create mode 100644 config/config.test.json create mode 100644 config/index.js diff --git a/app.js b/app.js index a5a7eff..49ab6f4 100644 --- a/app.js +++ b/app.js @@ -2,7 +2,7 @@ var _ = require('lodash'), express = require('express'), errors = require('http-error-factories'); -var config = require('./config.json'); +var config = require('./config'); var middleware, port = config.port, diff --git a/config.json b/config.json deleted file mode 100644 index decb0da..0000000 --- a/config.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "port": 3202, - "secret": "dea5e72e8c569c55aac94d8f838e66a9b5a394a5cb967bfe8a7597471bfcac4a149b6c04c525d6235c1d9935b0f311b2" -} diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..f5ed717 --- /dev/null +++ b/config/config.json @@ -0,0 +1,4 @@ +{ + +} + diff --git a/config/config.test.json b/config/config.test.json new file mode 100644 index 0000000..f5ed717 --- /dev/null +++ b/config/config.test.json @@ -0,0 +1,4 @@ +{ + +} + diff --git a/config/index.js b/config/index.js new file mode 100644 index 0000000..2529fc7 --- /dev/null +++ b/config/index.js @@ -0,0 +1,22 @@ +var confilter = require('confilter'), + path = require('path'); + +module.exports = confilter([ + + // Paths to load config files from + confilter.loadJSON([ + path.resolve(__dirname, 'config.' + process.env.NODE_ENV + '.json'), + path.resolve(__dirname, 'config.json') + ]), + + // Any defaults to fill in when missing from the config + confilter.defaults({ + port: 3200 + }, true), + + // Any defaults to fill in when missing from the config + confilter.required([ + // List required keys here + ]) +]); + diff --git a/package.json b/package.json index 147242b..f66e5e3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "index.js", "scripts": { "start": "WORKERS=2 node index | ./node_modules/bunyan/bin/bunyan", - "test": "jshint . && NODE_ENV=test ./node_modules/mocha/bin/mocha", + "test": "node_modules/jshint/bin/jshint && ./node_modules/mocha/bin/mocha", "cover": "NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", "config": "node tools/config" }, @@ -21,6 +21,7 @@ }, "dependencies": { "bunyan": "^0.23.1", + "confilter": "0.0.1", "express": "^4.6.1", "http-error-factories": "0.0.1", "lodash": "^2.4.1"