From 96d9719dafe86ac801d79eed4406f7b528923f2f Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Tue, 28 Jan 2014 12:48:29 -0500 Subject: [PATCH] Automatically try to re-connect to MongoDB every 5 seconds in case of connection.error --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 53c16f6728..dea4a69972 100755 --- a/app.js +++ b/app.js @@ -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();