-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
24 lines (19 loc) · 885 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
const mongoose = require('mongoose');
require('dotenv').config();
const connectToMongo=async()=>{
try {
if (process.env.DATABASE_ID == null) {
const conn = await mongoose.connect('mongodb://127.0.0.1:27017/meranote')
.then(() => { console.log("successfully connected with mongo"); })
.catch((err)=>{console.log(err)});
}
else {
const conn = await mongoose.connect(`mongodb+srv://${process.env.DATABASE_ID}:${process.env.DATABASE_PASS}@cluster0.4m23f.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`, { useNewUrlParser: true})
.then(() => { console.log("successfully connected with mongo atlas")})
.catch((err) => { console.log(err) });
}
} catch (error) {
console.log(error);
}
}
module.exports = connectToMongo;