I want to check if a file exists with nodejs from Electron. But I can't return a boolean value such as "true" or "false". The callback function doesn't return anything. Apparently the callback function executes after the main function. I tried many methods and nothing happens.
function fileExists(filename){
    var result;
    fs.stat(filename, function(err, stat) {
        if(err === null) {
            result = true;
        } else if(err.code == 'ENOENT') {
            result = false;
        }
    });
    return result;
}
//usage
if(fileExists('myFile.txt') === true){
    //proceed
}else{
    //error
}
