forked from dkantz/nodejs-tutorialspoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadwritefile.js
More file actions
32 lines (26 loc) · 784 Bytes
/
readwritefile.js
File metadata and controls
32 lines (26 loc) · 784 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
29
30
31
32
const fs = require("fs");
//const data = fs.readFileSync('input.txt');
//console.log(data.toString());
//console.log("Program Ended");
fs.readFile('input.txt', (err, data) => {
if (err){
console.log(err.stack);
return;
}
console.log(data.toString());
});
console.log("Program Ended");
console.log("Going to write into existing file");
fs.writeFile('input.txt', 'Simply Easy Learning Node!', function(err) {
if (err) {
return console.error(err);
}
console.log("Data written successfully!");
console.log("Let's read newly written data");
fs.readFile('input.txt', function (err, data) {
if (err) {
return console.error(err);
}
console.log("Asynchronous read: " + data.toString());
});
});