Created
January 23, 2018 13:59
-
-
Save vickonrails/347a5db7670f559fe0a1b080dc574a7c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //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