title: How to get list of databases in MongoDB using NodeJs?
body: <p>I have seen answers on C# and Java but not able to find anything on NodeJs. I have tried using cmd shell in Windows to get the required output but no luck.</p>
  
  <p>I am aware that the same information can be taken in Mongo shell but the requirement is to get a list within the NodeJs app.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> cmd = child_process.exec('"C:\\Program Files\\MongoDB\\Server\\3.2\\bin\\mongo.exe" admin ; db.getMongo().getDBNames()');</code></pre>
  </div>
  </div>
  </p>
  
  <p>and also</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mongoServer = require('mongodb-core').Server;
  
   var server = new mongoServer({
      host: 'localhost'
      , port: 27017
      , reconnect: true
      , reconnectInterval: 50   });
  
    server.on('connect', function (_server) {
  
    console.log('connected');
  
   var cmdres = _server.command('db.adminCommand({listDatabases: 1})');
  
   console.log("Result: " + cmdres);
  
  }</code></pre>
  </div>
  </div>
  </p>