Last active
December 10, 2016 09:39
-
-
Save asad01304/7604733 to your computer and use it in GitHub Desktop.
Mongoose Js bootstrapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dbConfig = { | |
db : null, | |
host : '127.0.0.1', | |
port : '27017', | |
name : 'test', | |
getConString : function(){ | |
return 'mongodb://' + this.host + | |
':' + this.port + '/' + this.dbName; | |
} | |
} | |
dbConfig.setup = function(){ | |
this.mongoose = require('mongoose'); | |
this.mongoose.connect(this.getConString()); | |
this.db = this.mongoose.connection; | |
this.db.on('error', console.error.bind(console, 'connection error:')); | |
this.db.once('open', function(){ console.log('mongoDb connected');}); | |
} | |
dbConfig.setup(); | |
module.exports = { | |
db : dbConfig.db, | |
mongoose : dbConfig.mongoose | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment