forked from HarkerRobo/robotics-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
35 lines (29 loc) · 780 Bytes
/
db.js
File metadata and controls
35 lines (29 loc) · 780 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
const mongoose = require("mongoose");
const config = require("./config.json");
mongoose.Promise = global.Promise;
mongoose.connect(
`mongodb://${
config.database.auth
? config.database.auth.username +
":" +
config.database.auth.password +
"@"
: ""
}localhost:${config.database.port}/${config.database.databaseName}`,
{
config: {
autoIndex: false,
},
useNewUrlParser: true,
useUnifiedTopology: true,
}
);
const db = mongoose.connection;
db.on("error", () => {
console.error("MongoDB connection error");
process.exit(1);
});
db.once("open", () => {
console.log("Successfully connected to MongoDB");
});
module.exports = mongoose;