Created
March 10, 2019 23:57
-
-
Save medmin/72d6627b9519abd9067d8b5af4119532 to your computer and use it in GitHub Desktop.
Nodejs (expressjs and Koajs) Mongoose Connect Config
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 mongoose = require('mongoose'); | |
mongoose.connect(`mongodb://dbUser:${encodeURIComponent('dbUserName')}@ds012889.mlab.com:12889/mLabDBname`, { useNewUrlParser: true }); | |
const db = mongoose.connection; | |
db.on('error', console.error.bind(console, 'connection error:')); | |
db.once('open', function () { | |
console.log('db ok'); | |
}); | |
module.exports = db; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment