Created
January 2, 2013 17:33
-
-
Save fnobi/4436348 to your computer and use it in GitHub Desktop.
fs.watchFileを使ってみた ref: http://qiita.com/items/b4588b2b37fe7136383d
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'); | |
var filepath = 'message.txt'; | |
// filepathが存在しなくても、watchFileはエラーとか出してくれないので、 | |
// 先にfs.existsで調べておく | |
if (!fs.existsSync(filepath)) { | |
console.error('%s doesn\'t exist.', filepath); | |
process.exit(); | |
} | |
console.log('start watch: %s', filepath); | |
fs.watchFile(filepath, function (curr, prev) { | |
// プロパティ丸ごと出力してもらう | |
console.dir(curr); | |
// 以前のmtimeと比較 | |
console.log('the current mtime is: ' + curr.mtime); | |
console.log('the previous mtime was: ' + prev.mtime); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment