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