-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
32 lines (25 loc) · 857 Bytes
/
db.js
File metadata and controls
32 lines (25 loc) · 857 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
32
const mongoose = require("mongoose");
require('dotenv').config();
//Define the mongodb connection URL
const mongoURL = process.env.mongoURL_Local; //Local Mongodb
// const mongoURL = process.env.mongoURL; //Online mongodb
//Set up mongodb Connect to the database
mongoose.connect(mongoURL, {
// useNewUrlParser: true,
// useUnifiedTopology: true
});
//Get the default connection
//mongoose maintaine connection reprent the mongodb connection
const db = mongoose.connection;
//Define event listern for data base connection
db.on("connected" , () =>{
console.log("MongoDB connection sucessfull ");
})
db.on("erroe" , (err) =>{
console.log("MongoDB connection Error " , err);
})
db.on("disconnected" , () =>{
console.log("MongoDB not connected ");
})
//Export the module
module.exports = db;