Skip to content

Commit

Permalink
just a change
Browse files Browse the repository at this point in the history
  • Loading branch information
nanda-mik committed May 19, 2020
1 parent 3302b00 commit a19bccf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
node_modules
util
.env
29 changes: 29 additions & 0 deletions util/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongodb = require('mongodb');
const MongoClient = mongodb.MongoClient;
const dotenv = require('dotenv');
dotenv.config();

let _db;

const mongoConnect = cb => {
MongoClient.connect(process.env.MONGODB_URI)
.then(client => {
console.log('Connected');
_db = client.db();
cb();
})
.catch(err => {
console.log(err);
throw err;
});
};

const getDb = () => {
if(_db){
return _db;
}
throw 'No database found';
};

exports.mongoConnect = mongoConnect;
exports.getDb = getDb;
3 changes: 3 additions & 0 deletions util/path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const path = require('path');

module.exports = path.dirname(process.mainModule.filename);

0 comments on commit a19bccf

Please sign in to comment.