Skip to content

Instantly share code, notes, and snippets.

@asad01304
Last active December 10, 2016 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asad01304/7604733 to your computer and use it in GitHub Desktop.
Save asad01304/7604733 to your computer and use it in GitHub Desktop.
Mongoose Js bootstrapping
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