diff --git a/app/db/db.config.js b/app/db/db.config.js new file mode 100644 index 0000000..390b5e9 --- /dev/null +++ b/app/db/db.config.js @@ -0,0 +1,9 @@ +module.exports = { + name: 'api-mooc', + host: process.env.HOST_MONGODB || '127.0.0.1:27017', + opts: { + promiseLibrary: global.Promise, + useNewUrlParser: true, + useCreateIndex: true, + }, +}; diff --git a/app/db/db.connect.js b/app/db/db.connect.js new file mode 100644 index 0000000..9f7747f --- /dev/null +++ b/app/db/db.connect.js @@ -0,0 +1,13 @@ +const mongoose = require('mongoose'); + +const UserSchema = require('../models/user'); +const NoteSchema = require('../models/note'); + +const db = require('./db.config'); + +mongoose.connect(`mongodb://${db.host}/${db.name}`, db.opts); + +mongoose.connection.on('connected', () => { + mongoose.model('User', UserSchema); + mongoose.model('Note', NoteSchema); +});