-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10.js
37 lines (37 loc) · 867 Bytes
/
10.js
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
const fs = require('fs');
const appendData = 'This data will be appended to the file.\n';
fs.appendFile('example.txt', appendData, (err) => {
if (err) {
console.error(err);
return;
}
console.log('Data appended to file!');
});
const content = 'This data will be written to the file.\n';
fs.open('example2.txt', 'w', (err, fd) => {
if (err) {
console.error(err);
return;
}
fs.writeFile(fd, content, (err) => {
if (err) {
console.error(err);
return;
}
console.log('File written successfully!');
fs.close(fd, (err) => {
if (err) {
console.error(err);
}
console.log('File closed successfully!');
});
});
});
const data = 'This data will overwrite the content of the file.\n';
fs.writeFile('example3.txt', data, (err) => {
if (err) {
console.error(err);
return;
}
console.log('File written successfully!');
});