title: mongoose connection failed with localhost while offline
body: <p>I am facing a issue while connecting to Mongodb using mongoose.<br>
  The problem is when i am offline it shows connection failed to localhost:27017
  but when i am online it connects successfully.<br>
  The code for reference is below:<br></p>
  
  <pre><code>mongoose.connect('mongodb://localhost/database');
  var db = mongoose.connection;
  db.on('error', function (err) {
  console.log('connection error', err);
  });
  db.once('open', function () {
  console.log('connected.');
  });
  </code></pre>
  
  <p>And here is the screenshot of both the situation.
  <a href="https://i.stack.imgur.com/f8xzk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f8xzk.png" alt="first command fails when there was no internet and second one connects successfully"></a></p>
  
  <p>Do I need to make some configuration in my system to make it work or It just work this way. </p>