Skip to content

Instantly share code, notes, and snippets.

@clonn
Created July 3, 2012 04:07
Show Gist options
  • Save clonn/3037620 to your computer and use it in GitHub Desktop.
Save clonn/3037620 to your computer and use it in GitHub Desktop.
Simple read file system on Node.js, let you know how to prevent checked file tiwce by curr time, prev time. Another is making you know how to get listener from watchFile API
var fs = require('fs');
var fullpath = '/home/clonn/test.html';
fs.watchFile(fullpath, function (curr, prev) {
if (curr.mtime.getTime() !== prev.mtime.getTime())
console.log('file update');
});
var fs = require('fs');
var fullpath = '/home/clonn/test.html';
var listen = fs.watchFile(fullpath, function (curr, prev) {});
listen.on('change', , function (curr, prev) {
if (curr.mtime.getTime() !== prev.mtime.getTime())
console.log('file update');
});
var fs = require('fs');
var fullpath = '/home/clonn/test.html';
fs.watchFile(fullpath, function (curr, prev) {
console.log('file update')
});
@clonn
Copy link
Author

clonn commented Jul 3, 2012

checked_file.js

make checking files to prevent display log twice by using current time, previous time.

checked_files_listen.js

Get listener from watchFile API, and let people know to using.

simple_watchfile.js

Simple watchFile API. it is simple, but it does not work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment