How to send json from nodejs server to client js file using Express and MongoDB
<p>I am new to Nodejs and Express and want to search some results from mongoDB and show it on client browser, i can find the values from the mongoDB query but not able to send it to client js file,
It says doc is not defined, any help will be appreciated.</p>

<pre><code>***app.js(Server)***
var bodyParser = require("body-parser");
var express = require("express");
var app = express();
var port = "8001";
var mongo= require('mongodb');
var mongoClient=mongo.MongoClient;
app.use(bodyParser.json());

app.use(express.static('public'));

app.get('/home', function(req, res) {
res.sendFile(__dirname + "/public/views/index.html");
});

app.listen(port, function() {
console.log("Server running at:" + port);
})

app.post("/response", function(req, res) {
var t = req.body;
mongoClient.connect("mongodb://localhost:27017/query", function(err,db){
cursor =db.collection('response').find({"name1":t.text},{"name2":1, "_id":0});
   cursor.each(function(err, doc) {
      if (doc != null) {
       console.log(doc);

      }

   });

})
res.send(doc);
});


***index.js(Client Side)***
$.ajax({
url: '/response',
type:"POST",
contentType:"application/json; charset=utf-8",
  complete: function(data) {
  console.log(data.responseText);
  alert(data.responseText);
}
});
</code></pre>