Skip to content

Commit

Permalink
Converted config to a module. Freeing the dependency on fs and the us…
Browse files Browse the repository at this point in the history
…e of readFileSync.
  • Loading branch information
Dan Thurman committed Jun 15, 2011
1 parent 67d809c commit fdb97bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
19 changes: 19 additions & 0 deletions config/config.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = config = {

This comment has been minimized.

Copy link
@isaacs

isaacs Jul 21, 2011

This creates a global "config" object. If that's not your intent, you should do var config = module.exports = { ...

If that is your intent, it'd be better to do module.exports = global.config = { ... so that it's clear that it's not an accident.

"name" : "Hummingbird",

"tracking_port" : 8000,
"dashboard_port" : 8080,

"mongo_host" : "localhost",
"mongo_port" : 27017,

"udp_address" : "127.0.0.1",
"udp_port" : 8000,

"enable_dashboard" : true,

"capistrano" : {
"repository" : "git://github.com/mnutt/hummingbird.git",
"hummingbird_host" : "hummingbird.your-host.com"
}
}
9 changes: 1 addition & 8 deletions server.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ require.paths.unshift(__dirname);


var http = require('http'), var http = require('http'),
weekly = require('weekly'), weekly = require('weekly'),
fs = require('fs'), config = require('./config/app.json'),
dgram = require('dgram'), dgram = require('dgram'),
static = require('node-static'), static = require('node-static'),
io = require('socket.io'), io = require('socket.io'),
mongo = require('mongodb'), mongo = require('mongodb'),
Hummingbird = require('hummingbird').Hummingbird; Hummingbird = require('hummingbird').Hummingbird;


try {
var configJSON = fs.readFileSync(__dirname + "/config/app.json");
} catch(e) {
console.log("File config/app.json not found. Try: `cp config/app.json.sample config/app.json`");
}
var config = JSON.parse(configJSON.toString());

db = new mongo.Db('hummingbird', new mongo.Server(config.mongo_host, config.mongo_port, {}), {}); db = new mongo.Db('hummingbird', new mongo.Server(config.mongo_host, config.mongo_port, {}), {});


db.addListener("error", function(error) { db.addListener("error", function(error) {
Expand Down

0 comments on commit fdb97bb

Please sign in to comment.