fs.watch("./", { recursive: true, encoding: "utf-8" }, (eventType, fileName)=>{
if(eventType === "change"){
console.log("[RESTART] on file changes -", fileName);
exec("node ./src/index.ts", (error, stdout, stderr)=>{
console.log(error);
});
}
});
I was trying to build a Nodemon clone, and I have written the logic above to try restart the program when there is some change in the file contents. But the exec() part does not work. What am I doing wrong here?