-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
20 lines (16 loc) · 821 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const mongoose = require('mongoose');
const config = require('config');
const chalk = require('chalk');
// Mongodb ServerUrl
const connectUrl = config.serverMongodb.url+''+config.serverMongodb.username+':'+config.serverMongodb.password+'@'+config.serverMongodb.serverUrl+'/'+config.serverMongodb.databaseName+'?retryWrites=true&w=majority';
// Mongodb LocalUrl
// const connectUrl = config.localMongodb.url+''+config.localMongodb.serverUrl+':'+config.localMongodb.port+'/'+config.localMongodb.databaseName;
mongoose.connect(connectUrl,{ useNewUrlParser:true, useUnifiedTopology: true },(err) => {
if(!err){
console.log(chalk.green('MongoDB connected...'));
} else
{
console.log(chalk.red('Error in DB connection: ' + JSON.stringify(err, undefined, 2)));
}
})
module.exports = mongoose