diff options
author | terminaldweller <thabogre@gmail.com> | 2022-03-25 14:36:57 +0000 |
---|---|---|
committer | terminaldweller <thabogre@gmail.com> | 2022-03-25 14:36:57 +0000 |
commit | 607b16ff74512cf70bb49efa553809bf9f5c8a84 (patch) | |
tree | 23a3bf0c5d84dfa36a447a44bf44c27a240b8fdb /model.js | |
parent | rss, WIP (diff) | |
download | blog-607b16ff74512cf70bb49efa553809bf9f5c8a84.tar.gz blog-607b16ff74512cf70bb49efa553809bf9f5c8a84.zip |
wip
Diffstat (limited to 'model.js')
-rw-r--r-- | model.js | 32 |
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; |