title: Connecting to mongodb through ssh username/password through nodejs
body: <p>I am trying to connect to Mongodb through ssh username/password through nodejs as below :</p>
  
  <pre><code>var mongoose = require('mongoose');
  var tunnel = require('tunnel-ssh');
  
  var config = {
  username : 'xyz',
  host: 'xx-xxx-xx.com',
  port:22,
  password:'xxx',
  dstPort:27017,
  localPort:27017
  };
  
  console.log(tunnel);
  var server = tunnel(config, function (error, server) {
  
  if(error){
      console.log("SSH connection error: " + error);
  }
  console.log(server);
  mongoose.connect('mongodb://localhost:27017/myDB');
  
  var db = mongoose.connection;
  console.log(db);
  db.on('error', console.error.bind(console, 'DB connection error:'));
  db.once('open', function() {
      console.log("DB connection successful");
  });
  });
  </code></pre>
  
  <p>But I am getting error as below :
  DB connection error: { MongoError: connection 0 to localhost:27017 timed out</p>
  
  <p>What is the issue here?</p>