Skip to content

Commit

Permalink
fix: Use new option for mongoose connect
Browse files Browse the repository at this point in the history
refactor: Split db connection and handling

style: disble quotes, arrow-parens
  • Loading branch information
oleg-koval committed Sep 11, 2018
1 parent 3b90344 commit f3c6fa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/database.js → lib/database/handling.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');

const config = require('../config');
// Connecting MongoDB using mongoose to our application
mongoose.connect(config.mongoConnectionString);

// This callback will be triggered once the connection is successfully established to MongoDB
mongoose.connection.on('connected', () => {
console.log(`Mongoose default connection open to ${config.mongoConnectionString}`);
});
mongoose.connection.on('connected', () => console.log('Mongoose default connection open'));

mongoose.connection.on('error', (err) => {
console.error({ err }, `Mongoose default connection error: ${err}`);
});
mongoose.connection.on('error', err => console.error({ err }, `Mongoose default connection error: ${err}`));

mongoose.connection.on('disconnected', () =>
console.log('Mongoose default connection disconnected'));
Expand Down
10 changes: 10 additions & 0 deletions lib/database/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');

const config = require('../../config');
// Connecting MongoDB using mongoose to our application
mongoose.connect(
config.mongoConnectionString,
{ useNewUrlParser: true }
);

0 comments on commit f3c6fa8

Please sign in to comment.