Automatically try to re-connect to MongoDB every 5 seconds in case of connection.error

This commit is contained in:
Sahat Yalkabov
2014-01-28 12:48:29 -05:00
parent 44d9730204
commit 96d9719daf

3
app.js
View File

@ -34,6 +34,9 @@ var passportConf = require('./config/passport');
mongoose.connect(secrets.db);
mongoose.connection.on('error', function() {
console.log('✗ MongoDB Connection Error. Please make sure MongoDB is running.'.red);
setTimeout(function() {
mongoose.connect(secrets.db);
}, 5000);
});
var app = express();