Skip to content
Browse files

first commit

  • Loading branch information...
0 parents commit 2388a49a7a2cbe0e7133c472bb23ab4f99e9d12d blahed committed
3 README.md
@@ -0,0 +1,3 @@
+## express-config
+
+Super simple express config loader. Looks for a config file in `./config/NODE_ENV` if `NODE_ENV` isn't set, it defaults to `./config/development.js`
1 index.js
@@ -0,0 +1 @@
+module.exports = require('./lib/express-config');
13 lib/express-config.js
@@ -0,0 +1,13 @@
+var path = require('path');
+
+module.exports = (function loadConfig () {
+ var config_dir = process.cwd() + '/config',
+ env = process.env.NODE_ENV || 'development',
+ config_file = config_dir + '/' + env + '.js';
+
+ if( path.existsSync(config_file) )
+ return require(config_file)
+ else
+ throw new Error("Config file not found. Try creating one here: `" + config_file + "'")
+})();
+
6 package.json
@@ -0,0 +1,6 @@
+{
+ "name": "express-config",
+ "description": "Super simple express config loader.",
+ "version": "0.0.1",
+ "main": "./index.js"
+}
3 test/config/development.js
@@ -0,0 +1,3 @@
+module.exports = {
+ foo: 'developing'
+}
3 test/config/production.js
@@ -0,0 +1,3 @@
+module.exports = {
+ foo: 'productioning'
+}
5 test/test_development_default.js
@@ -0,0 +1,5 @@
+var assert = require('assert'),
+ config = require('..');
+
+assert.ok(config.foo);
+assert.equal(config.foo, 'developing');
10 test/test_no_config.js
@@ -0,0 +1,10 @@
+process.env.NODE_ENV = 'testing';
+
+var assert = require('assert');
+
+assert.throws(
+ function() {
+ var config = require('..');
+ },
+ /^Error: Config file not found/gi
+);
7 test/test_production.js
@@ -0,0 +1,7 @@
+process.env.NODE_ENV = 'production';
+
+var assert = require('assert'),
+ config = require('..');
+
+assert.ok(config.foo);
+assert.equal(config.foo, 'productioning');

0 comments on commit 2388a49

Please sign in to comment.
Something went wrong with that request. Please try again.