Javascript nodejs fs.watch异步方式
我试图找出上传文件时文件夹中的哪个文件被更改。为此,我尝试使用fs.watch。我用Javascript nodejs fs.watch异步方式,javascript,node.js,fs,Javascript,Node.js,Fs,我试图找出上传文件时文件夹中的哪个文件被更改。为此,我尝试使用fs.watch。我用 const watcher = fs.watch(watchDir, (eventname, filename) => { console.log("Watcher: " + filename); }); //Code const getCookie = ClientFunction(() => { return document.cookie; }); let xmlresult =
const watcher = fs.watch(watchDir, (eventname, filename) => {
console.log("Watcher: " + filename);
});
//Code
const getCookie = ClientFunction(() => {
return document.cookie;
});
let xmlresult = await helpers.getXMLInfo('', testCorpusid, caseid);
console.log("Test message");
//Code
watcher.close()
但是//Code部分中似乎没有任何内容没有执行。我想我有点误解了,对吧?有人能给我一个提示,如何观看文件夹异步吗?您必须在回调函数中的每个文件更改上运行所需的代码,如下所示:
const watcher = fs.watch(watchDir, async (eventname, filename) => {
console.log("Watcher: " + filename);
const getCookie = ClientFunction(() => {
return document.cookie;
});
let xmlresult = await helpers.getXMLInfo('', testCorpusid, caseid);
console.log("Test message");
});
阅读有关回调的更多信息。我也尝试过这个方法,但不允许使用wait。。。。