Node.js comes with builtin method
fs.watch() method that will emit ‘change’ event whenver specific directory or file is modified
Save above code in
watch.js file and run the program
node watch.js. Make sure you change folder or file name.
Once you run the program, it will continuosly watch for any changes in specific folder or file and prints buffer once the changes are found.
Make some changes in folder or file being watched and check the console. You should see buffer on your terminal as shown below - contents of buffer may differ