-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5-fs_write_read.js
More file actions
28 lines (24 loc) · 835 Bytes
/
Copy path5-fs_write_read.js
File metadata and controls
28 lines (24 loc) · 835 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
//without callback
const {readFileSync, writeFileSync} = require('fs');
const first = readFileSync('./testFolder/first.txt', 'utf8');
const second = readFileSync('./testFolder/second.txt', 'utf8');
console.log(first, second);
writeFileSync('./testFolder/third.txt', 'its new file');
// second read write with callback - Async
const {readFile, writeFile} = require('fs');
readFile('./testFolder/first.txt', 'utf8', (err, data) => {
if(err){
console.log(err);
return;}
const first = data;
readFile('./testFolder/second.txt', 'utf8', (err, data) => {
if(err){
console.log(err);
return;}
const second = data;
writeFile('./testFolder/4th result.txt', `${first} ${second}`, (err) => {
if(err)
console.log(err);
});
})
});