So I have the following code
var processed;
fs.readFile(path, 'utf-8', function(err, data) {
    processed = false;
    //checking if text is in file and setting flag
    processed = true;
});
if (processed == true) {
    try {
        var fname = path.substring(path.lastIndexOf("\\") + 1);
        fs.moveSync(path, './processedxml/' + fname, {
            overwrite: true
        })
    } catch (err) {
        console.log("Error while moving file to processed folder " + err);
    }
}
But I don't get the desired output. Because looks like the readfile is executed by a separate thread and so the value of "processed" is not reliable.
I am not very familiar with nodejs so any help will be greatly appreciated.
 
     
     
    