-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path10- FS-Sync module.js
More file actions
25 lines (19 loc) · 875 Bytes
/
Copy path10- FS-Sync module.js
File metadata and controls
25 lines (19 loc) · 875 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
// FS, BUILT-IN MODULE - Interacting with the filesistem
//Essencially we can use it asyncronously and non-blocking, or syncronously wich will be blocking (later we'll se the diferences and when to use each other)
const {readFileSync, writeFileSync} = require("fs");
//read from fylesistem
const first = readFileSync('./content/first.txt','utf8');
const second = readFileSync('./content/second.txt','utf8');
console.log(first,'\n',second);
//if we have no file in the sistem when we use writeFileSync(), it will create it there.
//it will delete the content if the file is already there.
writeFileSync(
'./content/result-sync (10).txt',
`Here is the result:\n${first},\n${second}`
)
//to append to the file : we need to use a third argument called flag
writeFileSync(
'./content/result-sync (10).txt',
`\nHere is the appending!!!`,
{flag: "a"}
)