forked from Elpugna/Node-Express-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11- FS-Async module.js
More file actions
43 lines (40 loc) · 1.22 KB
/
11- FS-Async module.js
File metadata and controls
43 lines (40 loc) · 1.22 KB
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
38
39
40
41
42
43
// FS, BUILT-IN MODULE - Interacting with the filesistem
const {readFile, writeFile} = require("fs");
//read from fylesistem
//we get the buffer if we don't specify the type of content
readFile(
"./content/first.txt", "utf8",
(err, result)=>{
if(err){
// throw new Error(err)
console.log(err);
// return;
}
const first = result;
console.log("1: ",result);
readFile(
"./content/second.txt", "utf8",
(err, result)=>{
if(err){
// throw new Error(err)
console.log(err);
// return;
}
const second = result;
console.log("2: ",result);
writeFile(
'./content/result-Async (11).txt',
`Here is the async result: \n${first}.\n${second}.`,
(err, result)=>{
if(err){
console.log(err);
return;
}
console.log(result);
}
)
}
)
}
)
//We have a Callback Hell here!