Synchronous: First it will read the file then execute the next statement.
Program:
Demo.txt (Before):
Demo.txt (After):
Output:
ASynchronous: It will read file and simultaneously execute the next statements.
Program:
Demo.txt:
Output:
Program:
var fs = require('fs'); var r = fs.readFileSync('demo.txt','utf8'); fs.writeFileSync('demo.txt', 'CODING ATHARVA') console.log(r); console.log('Hey There');
Demo.txt (Before):
Demo.txt (After):
Output:
ASynchronous: It will read file and simultaneously execute the next statements.
Program:
var fs = require('fs'); fs.readFile('demo.txt','utf8',function(err,data){ console.log(data); }); console.log('Hey There');
Demo.txt:
Output: