mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 16:22:44 +00:00
[NFC] Outline database connection into a separate file
This commit is contained in:
14
server.js
14
server.js
@@ -77,16 +77,10 @@ const config = require('nconf')
|
||||
.file('environment', { file: `config/${process.env.NODE_ENV}.json` })
|
||||
.file('defaults', { file: 'config/default.json' });
|
||||
|
||||
//DB
|
||||
const mongoose = require('mongoose');
|
||||
mongoose.connect(config.get('mongodb_uri') || config.get('mongolab_uri') || 'mongodb://localhost/naturalcrit',
|
||||
{ retryWrites: false });
|
||||
mongoose.connection.on('error', (err)=>{
|
||||
console.log('Error : Could not connect to a Mongo Database.');
|
||||
console.log(' If you are running locally, make sure mongodb.exe is running.');
|
||||
console.log(err);
|
||||
throw 'Can not connect to Mongo';
|
||||
});
|
||||
// DB
|
||||
const DB = require('./server/db.js');
|
||||
// FIXME: consider implementing error hanlding for a Promise returned by connect
|
||||
DB.connect(config);
|
||||
|
||||
//Account Middleware
|
||||
app.use((req, res, next)=>{
|
||||
|
||||
Reference in New Issue
Block a user