forked from goldpriceapidb/gold-price
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.js
More file actions
36 lines (32 loc) · 871 Bytes
/
Copy pathdatabase.js
File metadata and controls
36 lines (32 loc) · 871 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
33
34
35
36
import mongoose from "mongoose"
mongoose.set("strictQuery", false)
class Database {
constructor() {
this._connect()
}
_connect() {
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(() => {
console.log("Database connection successful")
})
.catch((err) => {
console.error("Database connection error")
console.log(err)
})
}
async start() {
return new Promise((resolve, reject) => {
mongoose.connection.on("connected", () => {
resolve()
})
mongoose.connection.on("error", (err) => {
reject(err)
})
})
}
}
export default Database