-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-filesystem_module.js
More file actions
37 lines (31 loc) · 853 Bytes
/
06-filesystem_module.js
File metadata and controls
37 lines (31 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//fs -filesysyem module
const { readFile, writeFile, readFileSync, writeFileSync } = require("fs");
const first = readFileSync("./context/first.txt", "utf8");
const second = readFileSync("./context/second.txt", "utf8");
// console.log(first, second)
writeFileSync(
"./context/result-sync.txt",
`this file is generated with writeFileSync:
${first}, ${second} and some additional another text`,
{ flag: "a" } //flag 'a' show file is being appended
);
//readFIle reading file requires encoding
readFile("./context/first.txt", "utf8", (err, result) => {
if (err) {
console.log(err);
return;
}
console.log(result);
});
//writefile
writeFile(
"./context/result2-sync.txt",
`here is the result,${first}, ${second} `,
(err, result) => {
if (err) {
console.log(err);
return;
}
console.log(result);
}
);