-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
24 lines (23 loc) · 657 Bytes
/
Copy pathdb.js
File metadata and controls
24 lines (23 loc) · 657 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
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(
process.env.DATABASE_URL,
{ useNewUrlParser: true, useUnifiedTopology: true },
(err) => {
if (err) {
console.log("Unable to connect database");
process.exit(1);
} else {
console.log("Successfully Connect To the Database.");
}
}
);
mongoose.set("useCreateIndex", true);
const db = mongoose.connection;
db.on("error", (err) => {
console.log(`There was an error connecting to the database: ${err}`);
});
db.once("open", () => {
console.log(`You have successfully connected to your mongo database: `);
});
module.exports = db;