-
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) · 631 Bytes
/
db.js
File metadata and controls
31 lines (22 loc) · 631 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
const mongoose=require('mongoose');
require('dotenv').config();
// define mongodb connection url
const mongoURL = process.env.MONGODB_localURL;
// const mongoURL = process.env.DB_URL;
// setup mongoose connection
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',()=>{
console.log(' mongoDB connection error');
})
db.on('disconnected',()=>{
console.log('momngoDB disconnected');
})
module.exports= db;