-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
31 lines (22 loc) · 644 Bytes
/
db.js
File metadata and controls
31 lines (22 loc) · 644 Bytes
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
31
import mongoose from "mongoose";
import {configDotenv} from "dotenv";
configDotenv()
const mongoUrl = process.env.MONGODB_URL_LOCAL
//eshtablishing the MongoDB connection
// const MongoDBUrl = process.env.MONGODB_URL
mongoose.connect(mongoUrl,{
useNewUrlParser: true,
useUnifiedTopology: true
})
const db = mongoose.connection;
//Define event Listeners for Database connections
db.on('connected',()=>{
console.log("Connected to MongoDB Server...")
})
db.on('error',(err)=>{
console.log("MongoDB connection error",err)
})
db.on('disconnected',()=>{
console.log("MongoDB server disconnected..")
})
export default db;