Node.js fs watch file

Description

Node.js fs watch file

var fs = require("fs");
console.log("Starting...");
var config = JSON.parse(fs.readFileSync("config.json"));
console.log("Config file: ", config);

fs.watchFile("config.json", function (current, previous) {
  console.log("Config file changed.");
  config = JSON.parse(fs.readFileSync("config.json"));
  console.log("Config file: ", config);
});/*from  ww  w.  java  2s  .co  m*/



PreviousNext

Related