I have 2 functions
module.exports = (app, express) ->
config = nconf.get("database:#{app.settings.env}")
switch app.settings.env
when 'production'
app.db = mongoskin.db("#{config.host}:#{config.port}/#{config.name}", {journal: false})
else
app.db = mongoskin.db("#{config.host}:#{config.port}/#{config.name}", {journal: false})
module.exports.db = (db , env) ->
config = nconf.get("database:#{env}")
switch env
when 'production'
db = mongoskin.db("#{config.host}:#{config.port}/#{config.name}", {journal: false})
else
db = mongoskin.db("#{config.host}:#{config.port}/#{config.name}?", {journal: false})
return db
At some places we are using the 2nd function. However, we would like to get rid of one function. How can we go about doing it without passing the app parameter ? Is there a better way to define the 1st function ?
Thanks, Raja.
Added a DBSingleton class and using that object everywhere.