Tôi đang cố gắng viết một tập lệnh node.js để theo dõi các thay đổi trong thư mục tệp, sau đó in các tệp bị thay đổi. Làm cách nào để sửa đổi tập lệnh này để nó xem một thư mục (thay vì một tệp riêng lẻ) và in tên của các tệp trong thư mục khi chúng được thay đổi?
var fs = require('fs'),
sys = require('sys');
var file = '/home/anderson/Desktop/fractal.png'; //this watches a file, but I want to watch a directory instead
fs.watchFile(file, function(curr, prev) {
alert("File was modified."); //is there some way to print the names of the files in the directory as they are modified?
});