-
Notifications
You must be signed in to change notification settings - Fork 0
/
readFile.js
44 lines (28 loc) · 959 Bytes
/
readFile.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
38
39
40
41
42
43
44
console.log("Created file system object");
var fs=require('fs');
console.log("Reading file");
// Way 1 using anonymous function
// fs.readFile('Dem.txt','utf8',function(err,data){ //Calling read asyncronously
// if (err) {
// return console.log(err);
// }
// console.log("Got file object "+data);
// });
// Way 2 using callback function expression
var c=function(err,data){
if (err) {
return console.log(err);
}
console.log("Got file object "+data);
};
fs.readFile('Dem.txt','utf8',c); //Calling read asyncronously
// // Way 3 using callback function declaration
// function callback(err,data){
// if (err) {
// return console.log(err);
// }
// console.log("Got file object "+data);
// };
// fs.readFile('Dem.txt','utf8',callback); //Calling read asyncronously
// var data=fs.readFileSync('Dem.txt','utf8'); //Calling read syncronously
// console.log("Got file object "+data);