From ce759b45a7cdc0fd9bab421bbc950cf8e6af2134 Mon Sep 17 00:00:00 2001 From: Beth Griggs Date: Tue, 19 May 2020 13:30:10 +0100 Subject: [PATCH] Chapter 2: file watching change --- Chapter02/file-watching/file.txt | 4 ++-- Chapter02/file-watching/watch.js | 6 ++++-- Chapter02/file-watching/watch2.js | 8 -------- 3 files changed, 6 insertions(+), 12 deletions(-) delete mode 100644 Chapter02/file-watching/watch2.js diff --git a/Chapter02/file-watching/file.txt b/Chapter02/file-watching/file.txt index 6f87cc6..70f8058 100644 --- a/Chapter02/file-watching/file.txt +++ b/Chapter02/file-watching/file.txt @@ -1,4 +1,4 @@ -HELLO! +dfadfHELLO! ls Hello again; gs @@ -9,4 +9,4 @@ HELLO! sdda dfsdf dsad - sdasd \ No newline at end of file + sdasd diff --git a/Chapter02/file-watching/watch.js b/Chapter02/file-watching/watch.js index 6269985..de804fc 100644 --- a/Chapter02/file-watching/watch.js +++ b/Chapter02/file-watching/watch.js @@ -1,6 +1,8 @@ const fs = require("fs"); const file = "./file.txt"; +const moment = require("moment"); -fs.watchFile(file, (current, previous) => { - return console.log(`${file} updated ${time}`); +fs.watch(file, (eventType, filename) => { + const time = moment().format("MMMM Do YYYY, h:mm:ss a"); + return console.log(`${filename} updated ${time}`); }); diff --git a/Chapter02/file-watching/watch2.js b/Chapter02/file-watching/watch2.js deleted file mode 100644 index de804fc..0000000 --- a/Chapter02/file-watching/watch2.js +++ /dev/null @@ -1,8 +0,0 @@ -const fs = require("fs"); -const file = "./file.txt"; -const moment = require("moment"); - -fs.watch(file, (eventType, filename) => { - const time = moment().format("MMMM Do YYYY, h:mm:ss a"); - return console.log(`${filename} updated ${time}`); -});