Automatically try to re-connect to MongoDB every 5 seconds in case of connection.error
This commit is contained in:
3
app.js
3
app.js
@ -34,6 +34,9 @@ var passportConf = require('./config/passport');
|
|||||||
mongoose.connect(secrets.db);
|
mongoose.connect(secrets.db);
|
||||||
mongoose.connection.on('error', function() {
|
mongoose.connection.on('error', function() {
|
||||||
console.log('✗ MongoDB Connection Error. Please make sure MongoDB is running.'.red);
|
console.log('✗ MongoDB Connection Error. Please make sure MongoDB is running.'.red);
|
||||||
|
setTimeout(function() {
|
||||||
|
mongoose.connect(secrets.db);
|
||||||
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
Reference in New Issue
Block a user