javascript - Node.js scope of a variable inside a function -
i getting started node.js, , on small program writing running problem when trying pass variable.
i have function pass line have read file. in function create mongoose model of line , try save database. working fine, in cases there wrong data , can't saved database save text file.
i added call save file, file gets created empty. when debugging code, console messages displayed , appears @ point in execution line empty string. proper way pass value ?
var parserecord = function (line) { var arrayofstring = line.tostring().split(" "); if (arrayofstring[0].substr(0,1) != '#'){ var dbrecord = new logentry({ logdatetime: arrayofstring[0] + ' ' + arrayofstring[1], serverip: arrayofstring[2], requestmethod: arrayofstring[3], uristem: arrayofstring[4], serverport:arrayofstring[6], clientip:arrayofstring[8], browsertype:arrayofstring[9], referrersite:arrayofstring[10], httpstatus:arrayofstring[11], bytessent:arrayofstring[12], bytesreceived:arrayofstring[13], elapsedtime:arrayofstring[14] }); dbrecord.save(function (err) { if (err) { // console.log("skipped 1 record"); // console.log("this skipped line:" + bufferedline); fs.appendfile('skippedrecords.txt', line, function (err) { if (err) console.log("could not write skipped record"); }); //skippedrecords++; } else { //insertedrecords++; } }) //dbrecord.print(); } }
thank suggestions. --md
Comments
Post a Comment