title: Mongodb connection error ( connection 0 to 127.0.0.1:27017 timed out)
body: <p>There are many questions for this issue. I looked almost all of them and tried to fix my connection error but I couldn't</p>
  
  <p>This is my code</p>
  
  <pre><code>    var MongoClient = require('mongodb').MongoClient;   
      var url = "mongodb://localhost:27017/mgdb";
  
      MongoClient.connect(url, function(err, db) {  
      if (err) throw err;  
      console.log("Database created!");  
      //db.close();  
   });
  </code></pre>
  
  <p>The code is super simple though.. The error has been thrown  and it says</p>
  
  <p><strong>MongoError: failed to connect to server [localhost;27017] on first connection [MongoError: connection 0 to localhost:27017 timed]</strong></p>
  
  <p>I did as answers for similar questions but all didn't fix my problem. please help me fix this.</p>