-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
45 lines (35 loc) · 1.11 KB
/
Copy pathdatabase.js
File metadata and controls
45 lines (35 loc) · 1.11 KB
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
33
34
35
36
37
38
39
40
41
42
43
const mongoose = require('mongoose');
const DATABASE_URL = process.env.DATABASE_URL || "mongodb://localhost:27017";
// mongoose.set('useNewUrlParser', true);
// mongoose.set('useUnifiedTopology', true);
// mongoose.set('useFindAndModify', false);
class Database{
constructor(){
this.connect();
}
connect(){
const DB_OPTIONS = {
dbName: 'TwitterCloneDB',
};
mongoose.connect(DATABASE_URL, DB_OPTIONS)
.then(()=>{
console.log("Connected Successfully..");
})
.catch((err)=>{
console.log("Database Connection Error" + err);
})
}
}
module.exports = new Database(); // initializing it's instance so as of now by only including the file the connection will establish
// or
// const connectDB = async (DATABASE_URL) => {
// try{
// const DB_OPTIONS = {
// dbName: 'TwitterCloneDB',
// };
// await mongoose.connect(DATABASE_URL, DB_OPTIONS);
// }
// catch (err){
// console.log("Database Connection Error" + err);
// }
// };