-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
34 lines (33 loc) · 826 Bytes
/
db.js
File metadata and controls
34 lines (33 loc) · 826 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
const mongoose = require("mongoose");
const auth = require("./model/auth");
const bcrypt = require("bcrypt");
async function ConnectToDB() {
mongoose.set("strictQuery", true);
mongoose
.connect(process.env.DB, {
useNewUrlParser: true,
useUnifiedTopology: true,
})
.then(async () => {
console.log("Connected To db.");
const admin = await auth.findOne();
if (!admin) {
const password = await bcrypt.hash("123", 10);
const new_admin = new auth({
password,
});
new_admin
.save()
.then(() => {
console.log("admin created");
})
.catch((err) => {
console.log(err);
});
}
})
.catch((err) => {
console.log(err);
});
}
module.exports = ConnectToDB;