我正在编写一个 node.js 程序,它需要监视(添加/删除/更新)文件夹中的文件。我正在使用 chokidar 观看文件。这是代码
async function updateIndexFile() {
console.log({ path });
const pathArray = []
// Chokidar Code
const options = {
ignored: /(^|[\/\\])\../, // ignore dotfiles
persistent: true
}
// Initialize watcher.
const watcher = chokidar.watch(path, options);
watcher
.on('add', async (path) => {
console.log(`File ${path} has been added`)
let answer = await prompt({
type: 'list',
name: 'adventure', // * Key
message: 'Choose your own adventure',
choices: ['Indexify', 'Undo'] // * Add Feature Names Here
})
console.log(answer);
}) // Run indexify again on these files
.on('change', path => console.log(`File ${path} has been changed`)) // Run indexify again on these files
.on('unlink', path => console.log(`File ${path} has been removed`)); // Run indexify again on these files
但是,我不能使用终端,因为 chokidar 正在观看文件。所以,我希望 chokidar 在后台观看文件。所以,我仍然可以提示用户更多问题并做我的事情。