Created
September 14, 2018 08:46
-
-
Save devesh2605/ac6cddf8f7a6822864ec762e588a7b15 to your computer and use it in GitHub Desktop.
Connect to MongoDB using promise
This file contains hidden or 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
const mongodb = require('mongodb'); | |
const MongoClient = mongodb.MongoClient; | |
const config = require('../config/config'); | |
const mongoUrl = config.MONGO_URL | |
exports.connectToDb = function () { | |
return new Promise((resolve, reject) => { | |
MongoClient.connect(mongoUrl, { | |
useNewUrlParser: true | |
}, function (err, db) { | |
if (err) { | |
reject(err); | |
return; | |
} | |
resolve(db); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment