I have encountered an issue with a function I created that is meant to read a file after a delay of 2 minutes.
function checkInLogs(logFilPath, logMessage){
setTimeout(() => {
fs.readFile(logFilPath, 'utf8', function (err,data){
console.log('I am inside the checkInLogs function')
})
}, 120000);
console.log('outside the function');
}
The function is being called using the following code:
fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms25', '[Port:8090] successfully started');
However, I am facing an issue where the code inside the setTimeout is not being executed. The message 'outside the function' is displayed in the console but the inner code is not running. I tried another approach by modifying the function as follows:
function checkInLogs(logFilPath, logMessage){
fs.exists(logFilPath, function(exists) {
fs.readFile(logFilPath, 'utf8', function (err,data){
console.log(data.toString());
console.log(err.toString());
})
})
}
and calling it like:
setTimeout(function() {
fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms21', '[Port:8090] successfully started')
}, 120000);
Unfortunately, despite trying different approaches, the code inside the setTimeout is still not executing. Any suggestions or solutions would be greatly appreciated.