I am writing a callback function in node.js but it is returning me an undefined value. Below is the code
exports.getRecord = (function(callback) {
return function(req, res) {
var recordName;
DBObject.record.find(jsonString, function(err, doc_record) {
doc_record.forEach(function(docRecordTravel) {
recordName = callback(docRecordTravel.recordCode);
console.log(recordName);
})
}
})(callbackFunc);
function callbackFunc(recordCode) {
var recordName;
DBObject.var_recordRack.find({
recordID: recordCode
}, function(err, record) {
record.forEach(function(recordLoop) {
recordName = recordLoop.recordName;
});
console.log("callback " + recordName);
return recordName
});
}
In callbackFunc it is showing me the recordName but when i return it it displays undefined. how can I return the value in call backs in node.js.