Skip to content

Commit 84c3820

Browse files
Node module to make data streams
1 parent 312b8b4 commit 84c3820

File tree

1 file changed

+22
-0
lines changed
  • NodeBasic/Lecture09/fileHandling

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
const fs = require("fs")
3+
4+
fs.readFile("./input.txt",'utf-8',(err,data) => {
5+
if(err)
6+
{console.log(err)}
7+
8+
console.log("File is started to read");
9+
const result = data.split("\n")
10+
.filter(el => !isNaN(el))
11+
.map(el => +el)
12+
.reduce((acc, val) => acc + val, 0)
13+
14+
fs.writeFile('./output.txt', result, (err) => {
15+
if (err)
16+
return console.log(err)
17+
18+
console.log("Done")
19+
})
20+
21+
});
22+

0 commit comments

Comments
 (0)