From f54c6adeeb61c5ea2f7409a7f6dac5fe4928014b Mon Sep 17 00:00:00 2001 From: Chopper Date: Tue, 24 Oct 2023 01:44:15 +0700 Subject: [PATCH] add: Core module --- 4. Core Module/app.js | 31 ++++++++++++++++++++++++ 4. Core Module/data/testAsynchronous.txt | 1 + 4. Core Module/data/testSynchronous.txt | 1 + 3 files changed, 33 insertions(+) create mode 100644 4. Core Module/app.js create mode 100644 4. Core Module/data/testAsynchronous.txt create mode 100644 4. Core Module/data/testSynchronous.txt diff --git a/4. Core Module/app.js b/4. Core Module/app.js new file mode 100644 index 0000000..8f1c145 --- /dev/null +++ b/4. Core Module/app.js @@ -0,0 +1,31 @@ +// Core module +// File system +const fs = require("node:fs"); + +// Write string to file synchronous +// try { +// fs.writeFileSync("data/testSynchronous.txt", "Hello World Synchronous"); +// } catch (error) { +// console.log(error.message); +// } + +// Write string to file asynchronous +// fs.writeFile( +// "data/testAsynchronous.txt", +// "Hello World from asynchronous", +// (e) => { +// console.log(e); +// } +// ); + +// Read the content of the file Synchronous +// const data = fs.readFileSync("data/testSynchronous.txt", "utf-8"); + +// console.log(data); + +// Read the content of the file Asynchronous +fs.readFile("data/testAsynchronous.txt", "utf-8", (err, data) => { + if (err) throw err; + + console.log(data); +}); diff --git a/4. Core Module/data/testAsynchronous.txt b/4. Core Module/data/testAsynchronous.txt new file mode 100644 index 0000000..6f47af8 --- /dev/null +++ b/4. Core Module/data/testAsynchronous.txt @@ -0,0 +1 @@ +Hello World from asynchronous \ No newline at end of file diff --git a/4. Core Module/data/testSynchronous.txt b/4. Core Module/data/testSynchronous.txt new file mode 100644 index 0000000..520ead9 --- /dev/null +++ b/4. Core Module/data/testSynchronous.txt @@ -0,0 +1 @@ +Hello World Synchronous \ No newline at end of file