htaidirt htaidirt - 2 years ago 96
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


Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download