Handling Mongo connection errors and starting bcoin once the db connects

This commit is contained in:
tenthirtyone 2017-08-04 10:53:00 -04:00
parent 63f60d06eb
commit 045c53accb
3 changed files with 12 additions and 1 deletions

View File

@ -12,6 +12,8 @@ const config = {
uri: 'mongodb://localhost/bitcore',
options: {
useMongoClient: true,
socketTimeoutMS: 0,
connectTimeoutMS: 0
},
},
api: {

View File

@ -14,4 +14,6 @@ Api.listen(config.api.port, () => {
'listening on port 3000');
});
node.start();
db.connection.once('open', function() {
node.start();
});

View File

@ -1,3 +1,10 @@
const mongoose = require('mongoose');
const logger = require('../logger');
mongoose.connection.on('error', (err) => {
logger.log('error',
`Failed to connect to Mongo Database
${err}`);
});
module.exports = mongoose;