Skip to content

Instantly share code, notes, and snippets.

@nojaf
Created November 14, 2016 10:28
Show Gist options
  • Save nojaf/44c3e6da3f3f4fe252f560931a5afea4 to your computer and use it in GitHub Desktop.
Save nojaf/44c3e6da3f3f4fe252f560931a5afea4 to your computer and use it in GitHub Desktop.
Watch a file and run a command using nodejs
const {watch} = require("fs");
const {exec} = require("child_process");
watch("myFolder/myFile.ascx", (eventType,fileName) => {
if(eventType == "change"){
console.log("myFile.ascx changed");
exec('xcopy "Some Folder\\myFile.ascx" "Other Folder\\" /Y', () => {
console.log("File copied");
});
}
});
console.log("Watching myFile.ascx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment