I have this function:
exports.readPartial = function(html, values, response) {
fs.readFile(__dirname + "/../html/partials/" + html, function(error, file) {
if(error) { this.loadError(response, error); }
else {
console.log("\t--> partial found: " + file);
return file; // FILE VALUE
}
});
}
When that function is called it should return the value of "file". However, when calling return file; im actually returning the value in the anonymous function I passed as an argument.
What is the right way to return this value on async programming with nodejs?
Using var that = this; ?
Got confused pretty confused with this style of programming.