Skip to content

Commit

Permalink
Simplify config to an object
Browse files Browse the repository at this point in the history
Converted the config from a setup function into an object that grabs
from the NODE_ENV to set the current configurations.  Also, config.js
was modified for a single object exported with module.exports -- the
node documentation prefers that module.exports uses as a single object.
  • Loading branch information
robertsprinting committed Jun 18, 2013
1 parent 634b469 commit 755873e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 57 deletions.
16 changes: 3 additions & 13 deletions app.js
@@ -1,10 +1,10 @@
var express = require('express');
var config = require('./config/config');

var app = module.exports = express.createServer();

// Check node_env, if not set default to development
process.env.NODE_ENV = (process.env.NODE_ENV || "development");
var env = (process.env.NODE_ENV || "development");
var config = require('./config/config')[env];

// Configuration, defaults to jade as the view engine
app.configure(function(){
Expand All @@ -20,18 +20,10 @@ app.configure(function(){
* This section is for environment specific configuration
*/
app.configure('development', function(){
config.setDevelopmentConfig();
console.log(config.DatabaseConfig);
console.log(config.EnvConfig);

app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
config.setProductionConfig();
console.log(config.DatabaseConfig);
console.log(config.EnvConfig);

app.use(express.errorHandler());
});

Expand All @@ -46,6 +38,4 @@ app.listen(config.EnvConfig.port, function(){
* all route matches go the routes.js file
*/
module.exports.app = app;
routes = require('./routes');


routes = require('./routes');
70 changes: 26 additions & 44 deletions config/config.js
@@ -1,44 +1,26 @@
/*
* modify values in these methods to set
* environment specific info
*/
function setDevelopmentConfig(){
// These are just examples, insert you info here
DatabaseConfig.port = 27617;
DatabaseConfig.host = '::mongo host::';
DatabaseConfig.name = '::collection name::';
DatabaseConfig.user = '::db username::';
DatabaseConfig.pass = '::db password::';

EnvConfig.port = 3000;
};

function setProductionConfig(){
DatabaseConfig.port = 29017;
DatabaseConfig.host = '::mongo host::';
DatabaseConfig.name = '::collection name::';
DatabaseConfig.user = '::db username::';
DatabaseConfig.pass = '::db password::';

EnvConfig.port = 80;
};

/* --- no need to modify below this line -- */


var DatabaseConfig = {
port : Number,
host : String,
name : String,
user : String,
pass : String
};

var EnvConfig = {
port : Number
};

module.exports.DatabaseConfig = DatabaseConfig;
module.exports.EnvConfig = EnvConfig;
module.exports.setDevelopmentConfig = setDevelopmentConfig;
module.exports.setProductionConfig = setProductionConfig;
module.exports = {
development: {
DatabaseConfig: {
port: 27617,
host: '::mongo host::',
name: '::collection name::',
user: '::db username::',
pass: '::db password::'
},
EnvConfig: {
port: 3000
}
},
production: {
DatabaseConfig: {
port: 29017,
host: '::mongo host::',
name: '::collection name::',
user: '::db username::',
pass: '::db password::'
},
EnvConfig: {
port: 80
}
}
};

0 comments on commit 755873e

Please sign in to comment.