Skip to content

Instantly share code, notes, and snippets.

@wilf312
Created February 17, 2014 19:51
Show Gist options
  • Save wilf312/9057706 to your computer and use it in GitHub Desktop.
Save wilf312/9057706 to your computer and use it in GitHub Desktop.
Nodejsで自前のwatchを作る ref: http://qiita.com/GENYA/items/0c8670a5200050acdb16
var fs = require('fs'); // ファイル操作
// ウォッチするファイルの指定と保存時に実行される処理の記述
createWatcher('path/to/hoge.txt', function() {
console.log("Callback");
});
// ウォッチのテンプレ。100msなので、監視対象が増えると辛いかもしれない。
function createWatcher(aTargetPath, aCallback) {
fs.watchFile(aTargetPath, { persistent: true, interval: 100 }, function(curr, prev) {
console.log("\n// ----------------- Saved ");
// 保存時にやりたい処理
aCallback();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment