htaidirt htaidirt - 5 months ago 27
Node.js Question

Node.js: Track new files in a directory

I would like to track new files in a directory. I used the script given in the documentation:

var fs = require('fs');'mydir/', function (event, filename) {
console.log('event is: ' + event);
if (filename) {
console.log('filename provided: ' + filename);
} else {
console.log('filename not provided');

And I added files to
touch hello.txt
for example.

When running the script, I don't get the new file name, because the emitted event is
!! Here is the console output.

event is: rename
filename not provided

How can I get the file new name



The same page also describes your issue:

Providing filename argument in the callback is not supported on every platform (currently it's only supported on Linux and Windows). Even on supported platforms filename is not always guaranteed to be provided.

I think your best bet is to switch to another module providing similar functionality, like watch (which I don't have any experience with myself).