Skip to content

Instantly share code, notes, and snippets.

@raisch
Created April 14, 2015 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raisch/537436cbf9cb3b1ebc8c to your computer and use it in GitHub Desktop.
Save raisch/537436cbf9cb3b1ebc8c to your computer and use it in GitHub Desktop.
'use strict';
const
fs = require('fs'),
filename = process.argv[2];
console.log('--watching %s',filename);
var watcher=fs.watch(filename);
watcher.on('change',function(){
console.log('--%s has changed.');
watcher.close();
let stream=fs.createReadStream(filename);
stream.on('data',function(chunk){
process.stdout.write(chunk);
});
stream.on('end',function(){
stream.close();
watcher=fs.watch(filename);
});
stream.on('error',function(err){
stream.close();
console.error('--failed to read from stream: %s', err);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment