Created
February 17, 2014 19:51
-
-
Save wilf312/9057706 to your computer and use it in GitHub Desktop.
Nodejsで自前のwatchを作る ref: http://qiita.com/GENYA/items/0c8670a5200050acdb16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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