title: MongoError: connect ECONNREFUSED 127.0.0.1:27017
body: <p>I'm using NodeJS wih MongoDB using mongodb package. When I run mongod command it works fine and gives &quot;waiting for connection on port 27017&quot;. So, mongod seems to be working. But MongoClient does not work and gives error when I run node index.js command-</p>
  <pre><code>MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
  </code></pre>
  <p><a href="https://i.stack.imgur.com/lXL3f.png" rel="noreferrer"><img src="https://i.stack.imgur.com/lXL3f.png" alt="enter image description here" /></a></p>
  <p>I have install mongo db 3.4 and my code is-</p>
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  var dburl       =   &quot;mongodb://localhost:27017/test&quot;;
  MongoClient.connect(dburl, function(err, db) {
    if (err) {
      throw err;
    }
    console.log('db connected');
    db.close();
  });
  </code></pre>
  <p>I have created data/db directories on root and given write permissions.
  mongod.conf file takes db path as-</p>
  <p>storage:
  dbPath: /var/lib/mongo</p>
  <p>But it seems that it is actually taking db path as data/db and not var/lib/mongo</p>
  <p>It working earlier but suddenly stopped.</p>