-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb.js
30 lines (24 loc) · 892 Bytes
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ---------------------------------------------------------------------------------
* @ description : This is the db configration file.
---------------------------------------------------------------------------------- */
import Mongoose from 'mongoose';
import Bluebird from 'bluebird';
import config from 'config';
import logger from './utilities/logger';
// Connect to MongoDB
const db = config.get('db');
export default async () => {
// Build the connection string.
const mongoUrl = db.auth
? `mongodb://${db.username}:${db.password}@${db.host}:${db.port}/${db.name}`
: `mongodb://${db.host}:${db.port}/${db.name}`;
Mongoose.Promise = Bluebird;
Mongoose.connect(mongoUrl, config.get('db.mongoose'), err => {
if (err) {
logger.error('+++ DB Error', err);
// process.exit(1);
} else {
logger.info('+++ MongoDB Connected');
}
});
};