Here is my code:
hArr = Array();
hash.find({ hash_name: new RegExp('^' + req.body.hash + '$', "i") }, function(err, doc) {
//Do your action here..
if (err) {
res.json({ response: 0, data: "fail", message: " Image Downloadding" });
} else {
for (var h = 0; h < doc.length; h++)
hArr.push(doc[h].img_name);
var unique = hArr.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
Image.find().where('img').in(unique).exec(function(err, result) {
res.json({ response: 1, data: result, message: "IMage List" });
})
}
});
and when I run this code it show
Listening for request
events.js:160
throw er; // Unhandled 'error' event
^
Error: Can't set headers after they are sent.
at ServerResponse.setHeader (_http_outgoing.js:359:11)
at ServerResponse.header (E:\learnNode\insta\node_modules\express\lib\response.js:730:10)
at ServerResponse.send (E:\learnNode\insta\node_modules\express\lib\response.js:170:12)
at ServerResponse.json (E:\learnNode\insta\node_modules\express\lib\response.js:256:15)
at E:\learnNode\insta\routes\api.js:830:25
at E:\learnNode\insta\node_modules\mongoose\lib\query.js:2819:18
at process._tickDomainCallback (internal/process/next_tick.js:129:7)