When the code below is executed, the clock only starts when I edit and save tmp.txt manually, using either my ide, TextEditor.app, or vim.
This is not a method of redirecting a recording stream or manually outputting a shell (entering the echo test "> /path/to/tmp.txt").
Although, if I look at the file itself, and not its name, it works.
var fs, Path, file, watchPath, w; fs = require('fs' ); Path = require('path'); file = __dirname + '/tmp.txt'; watchPath = Path.dirname(file); // changing this to just file makes it trigger w = fs.watch ( watchPath, function (e,f) { console.log("will not get here by itself"); w.close(); }); fs.writeFileSync(file,"test","utf-8"); fs.createWriteStream(file, { flags:'w', mode: 0777 } ) .end('the_date="'+new Date+'";' ); // another method fails as well setTimeout (function () { fs.writeFileSync(file,"test","utf-8"); },500); // as does this one // child_process exec and spawn fail the same way with or without timeout
So the questions are: why? and how to programmatically fire this event from a node script?
Thanks!
source share