-
Notifications
You must be signed in to change notification settings - Fork 4
/
db.js
20 lines (18 loc) · 843 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 DB_PATH = process.env.DB_PATH || `mongodb+srv://Decoder:${process.env.DB_PASS}@decodercluster.eyv5r.mongodb.net/${process.env.DB_NAME}?retryWrites=true&w=majority`; //* Url for node
// const DB_PATH = `mongodb+srv://Decoder:${process.env.DB_PASS}@decodercluster.eyv5r.mongodb.net/test`; //* Url For Compass
// console.log('DB Path : ', DB_PATH);
module.exports.connectWithDatabase = async () => {
try {
const connection = await mongoose.connect(DB_PATH, {
useUnifiedTopology: true,
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
});
console.log(`Connected with Database : ${connection.connection.host}`);
} catch (error) {
console.log(error.message);
process.exit(1);
}
};