Created
April 14, 2015 20:20
-
-
Save raisch/537436cbf9cb3b1ebc8c to your computer and use it in GitHub Desktop.
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
'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