nodejs-dac-examples
Version:
23 lines (18 loc) • 850 B
JavaScript
/********************File IO example*****************/
var fs = require('fs');//Core Nodejs modules dont need relative path as they are available globally
//readFileSync function is used to read a specific file in a synchronous manner.
/*var contents = fs.readFileSync("FirstExample.js", 'utf8');
//text format....
console.log(contents)
*/
//readFile function is used to read a file asynchronously so that the app will not wait for the file to be read completely. This is used for large files where the content would a longer duration to read the whole file...
//It uses call back function to be invoked after the file is read.
fs.readFile('CoreModules.js', 'utf8', function(err, content){
if(err)
console.log(err);
else
console.log(content)
});
for(var i = 0; i < 10; i++) {
console.log("Work is going on.....")
}