我正在使用fs.createWriteStream和morgan将日志写入文本文件。下面是监视文件中所做更改的代码,但是它无法检测到更改。
fs.watch(loggerFile, (event, filename) => {
if (filename) {
if (fsWait) return;
fsWait = setTimeout(() => {
fsWait = false;
}, 100);
const md5Current = md5(fs.readFileSync(loggerFile));
if (md5Current === md5Previous) {
return;
}
md5Previous = md5Current;
sails.log(`${filename} file Changed`);
}
});