diff --git a/lib/database.js b/lib/database.js new file mode 100644 index 0000000..6c0a47f --- /dev/null +++ b/lib/database.js @@ -0,0 +1,25 @@ +/** + * A custom library to establish a database connection + */ +'use strict'; +var mongoose = require('mongoose'); + +var db = function () { + return { + + /** + * Open a connection to the database + * @param conf + */ + config: function (conf) { + mongoose.connect('mongodb://' + conf.host + '/' + conf.database); + var db = mongoose.connection; + db.on('error', console.error.bind(console, 'connection error:')); + db.once('open', function callback() { + console.log('db connection open'); + }); + } + }; +}; + +module.exports = db(); \ No newline at end of file diff --git a/package.json b/package.json index 9991f8a..710f1aa 100644 --- a/package.json +++ b/package.json @@ -1,33 +1,34 @@ { - "name": "kraken-example-shopping-cart", - "version": "0.0.1", - "description": "A non-trivial kraken app", - "author": "@LennyMarkus", - "main": "index.js", - "scripts": { - "test": "grunt test", - "start": "node index.js" - }, - "engines": { - "node": ">=0.10.0" - }, - "dependencies": { - "kraken-js": "~0.6.1", - "express": "~3.4.4", - "adaro": "~0.1.x", - "nconf": "~0.6.8", - "less": "~1.3.3", - "dustjs-linkedin": "~2.0.3", - "dustjs-helpers": "~1.1.1", - "makara": "~0.3.0" - }, - "devDependencies": { - "mocha": "~1.10.0", - "grunt": "~0.4.1", - "grunt-contrib-less": "~0.7.0", - "grunt-dustjs": "~1.1.1", - "grunt-contrib-clean": "~0.5.0", - "grunt-contrib-jshint": "~0.6.4", - "grunt-mocha-cli": "~1.3.0" - } + "name": "kraken-example-shopping-cart", + "version": "0.0.1", + "description": "A non-trivial kraken app", + "author": "@LennyMarkus", + "main": "index.js", + "scripts": { + "test": "grunt test", + "start": "node index.js" + }, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "kraken-js": "~0.6.1", + "express": "~3.4.4", + "adaro": "~0.1.x", + "nconf": "~0.6.8", + "less": "~1.3.3", + "dustjs-linkedin": "~2.0.3", + "dustjs-helpers": "~1.1.1", + "makara": "~0.3.0", + "mongoose": "~3.8.1" + }, + "devDependencies": { + "mocha": "~1.10.0", + "grunt": "~0.4.1", + "grunt-contrib-less": "~0.7.0", + "grunt-dustjs": "~1.1.1", + "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-jshint": "~0.6.4", + "grunt-mocha-cli": "~1.3.0" + } }