javascript - error while using async in node.js -
i trying write restapi using express framework , node.js. facing error unable find out root cause. getting following error while trying execute code :
typeerror: cannot read property 'node_type' of undefined
'node_type' value comes function
var gdbprocess = require('../../dao/gdb/processnds') var mongo = require('mongodb'); var async = require('async'); exports.executeservice = function(req,res){ //make process object query var manualprocessquery = new object(); manualprocessquery.index = req.params.processmap; manualprocessquery.key = "pid"; manualprocessquery.value = req.params.pid; manualprocessquery.event = req.params.event; var tempdatanodetoexecute = new object(); //this function returns object (datanodetoexecute) execute gdbprocess.getparametersbynode(manualprocessquery,function(err,datanodetoexecute){ if(err) res.send(err); tempdatanodetoexecute = datanodetoexecute; var issystem = false; if (tempdatanodetoexecute.node_type =="system"){ issystem = true; } var count = 0; async.whilst( function () { return issystem }, function (callback) { //execute function executesystem(datanodetoexecute,function(err,executionstatus){ if (err) callback(err); count++; if(executionstatus=="completed"){ manualprocessquery.value = tempdatanodetoexecute.pid; manualprocessquery.event = "completed"; gdbprocess.getparametersbynode(manualprocessquery,function(err,datanodetoexecute2){ if(err) callback(err); tempdatanodetoexecute = datanodetoexecute2; if (tempdatanodetoexecute.node_type == "manual"){ issystem = false; } }); callback(); } }); }, function (err) { if(err) res.send(err); res.send("success"); } ); }); } var executemanual = function(prosnodetoexecute,callback){ //do callback (null); } var executesystem = function(prosnodetoexecute,callback){ //do callback(null,"completed"); }
when debug code, see node_type available. can me find root problem here ?
remove new object tempdatanodetoexecute , use datanodetoexecute instead of it, , practice check null of object before using property program not crashes.
Comments
Post a Comment