Database config

pull/1/head
sundowndev 2018-11-13 18:46:28 +01:00
parent b1abecc262
commit 51ab76f613
2 changed files with 22 additions and 0 deletions

9
app/db/db.config.js Normal file
View File

@ -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,
},
};

13
app/db/db.connect.js Normal file
View File

@ -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);
});