aboutsummaryrefslogtreecommitdiffstats
path: root/model.js
diff options
context:
space:
mode:
authorterminaldweller <thabogre@gmail.com>2022-03-25 14:36:57 +0000
committerterminaldweller <thabogre@gmail.com>2022-03-25 14:36:57 +0000
commit607b16ff74512cf70bb49efa553809bf9f5c8a84 (patch)
tree23a3bf0c5d84dfa36a447a44bf44c27a240b8fdb /model.js
parentrss, WIP (diff)
downloadblog-607b16ff74512cf70bb49efa553809bf9f5c8a84.tar.gz
blog-607b16ff74512cf70bb49efa553809bf9f5c8a84.zip
wip
Diffstat (limited to 'model.js')
-rw-r--r--model.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/model.js b/model.js
new file mode 100644
index 0000000..7eba2a4
--- /dev/null
+++ b/model.js
@@ -0,0 +1,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;