Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active November 6, 2018 00:43
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 jgwill/82dd3b917a5d0007900f340203a484cf to your computer and use it in GitHub Desktop.
Save jgwill/82dd3b917a5d0007900f340203a484cf to your computer and use it in GitHub Desktop.
node.js - Watch a folder and execute an action when that happen
//@a Watch a folder and do something with the changes
var watchPath = "/www/x/fs_watch_folder_1811051535/tests";
console.log("Watching test path: " + watchPath);
var fs = require("fs");
var sleep = require("sleep");
fs.watch(watchPath, (eventType, filename) => {
console.log(eventType);
// could be either 'rename' or 'change'. new file event and delete
// also generally emit 'rename'
console.log(filename);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment