Skip to content

Instantly share code, notes, and snippets.

@vickonrails
Created January 23, 2018 13:59
Show Gist options
  • Select an option

  • Save vickonrails/347a5db7670f559fe0a1b080dc574a7c to your computer and use it in GitHub Desktop.

Select an option

Save vickonrails/347a5db7670f559fe0a1b080dc574a7c to your computer and use it in GitHub Desktop.
//filewatcher.js
const net = require('net'),
fs = require('fs'),
filename = process.argv[2],
server = net.createServer((connection)=>{
console.log('Subscriber connected');
connection.write(`watching ${filename} for changes`);
let watcher = fs.watch(filename,(err,data)=>{
connection.write(`${filename} has changed`);
});
connection.on('close',()=>{
console.log('Subscriber disconnected');
watcher.close();
});
});
server.listen(3000,()=>console.log('listening for subscribers'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment