blob: 7eba2a4b1ea7ea298726d743c04ae420486ca6a3 (
plain) (
blame)
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
|
"use strict";
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
const db = {};
db.mongoose = mongoose;
db.url = "mongo:27017";
const blogPostModel = mongoose.model(
"blogPost",
mongoose.Schema(
{
title: String,
description: String,
published: Boolean,
},
{ timestamps: true }
)
);
function dbInit() {
db.mongoose
.connect(db.url, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => {
console.log("successfully connected to db");
})
.catch((err) => {
console.log("cannot connect to the database: ", err);
process.exit(1);
});
}
module.exports = dbInit;
|