You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: en/file-system/README.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,8 +16,8 @@ In this example, you are using the `fs.readFile` function to read data from the
16
16
17
17
```javascript
18
18
constfs=require('fs');
19
-
//async
20
-
//non blokcing i/0 thats why runs at last as ti takes moer time
19
+
//asynchronous, non-blocking I/O that's why this runs last, as it takes more time
20
+
21
21
fs.readFile('test.txt','utf8',(err,data) => {
22
22
console.log(err,data)
23
23
})
@@ -29,7 +29,7 @@ Here, you use fs.writeFile to write data to the 'test.txt' file asynchronously.
29
29
30
30
```javascript
31
31
fs.writeFile("test.txt","mahima is good girl", () => {
32
-
console.log("This runs after writting in a file: written to file")
32
+
console.log("This runs after writing in a file: written to file")
33
33
})
34
34
```
35
35
@@ -41,7 +41,7 @@ Synchronous I/O operations block the execution of the program until the operatio
41
41
The `fs.readFileSync` function is used for synchronous file reading. It blocks the execution until the entire file is read, and then it continues with the rest of the code. This is generally not recommended because it can cause the program to become unresponsive during the file read.
fs.writeFileSync("test.txt","mahima is good girl",() => {
56
-
console.log("This is sync: intentionally process is blocked ")
57
-
})
55
+
fs.writeFileSync("test.txt","mahima is good girl", 'utf8')
56
+
console.log("This is sync: the process is intentionally blocked ")
58
57
59
58
```
60
59
Node.js provides both synchronous and asynchronous file I/O options. Asynchronous I/O is typically preferred for better performance and responsiveness, while synchronous I/O is used only when necessary and with caution, as it can block the program's execution.
0 commit comments