Can someone please explain why some variables are not passed to readFile
's callback, while others are?
// response is http response writer obj
var process = function (response, file) {
var calculator = new mycalc.Calculator();
var output1 = "no-error";
var that = this;
try {
fs.readFile(file, 'utf8', function (err, data) {
if (err) {
that.output1 = "check1";
}
output1 = "check2";
response.write(output1);
// not even working with that.output1
// more stuff will come here
});
} catch (e) {
response.write(e.stack);
}
response.write(output1);
};
Issues:
response.write()
doesn't write within the callback function but it does write successfully fromprocess()
function scope.output1
prints "no-error", while the expected result is "check1" or "check2"