title: How to set MongoClient connection timeout?
body: <p>I have a server which first connects to MongoDB instance, then starts web server. If MongoDB instance is not available, there is no point to start web server, so I think I need to somehow set a timeout to, say 5 seconds.</p>
  
  <p>How do I do it?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>MongoClient.connect(Config.database.url).then((db) =&gt; {
          console.log('Connected to MongoDB');
          databaseInstance = db;
         // start web server
      })
  </code></pre>