Wenn der unten stehende Code ausgeführt wird, wird die Uhr nur ausgelöst, wenn ich tmp.txt manuell editiere und speichere, entweder mit meinem IDE, TextEditor .app oder vim.NodeJS fs.watch im Verzeichnis wird nur ausgelöst, wenn vom Editor geändert, aber nicht Shell oder fs Modul
Es ist nicht durch Verfahren des Schreibstroms oder manueller Shell Ausgabeumleitung (Eingabe echo „test“> /path/to/tmp.txt ").
Obwohl, wenn ich die Datei selbst sehen, und . nicht seine dirname, dann funktioniert es
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 sind die Fragen: warum und wie dieses Ereignis von einem Knoten Skript programmatisch triggern
Dank
nur fs.watch ändern -> fs.watchFile und fertig. ref: [Git-Link] (https://github.com/joyent/node/issues/3640) – mayankcpdixit