Friday, 26 August 2016

Read Data from File in Node.js

# Below is the code to Read data from File there are tow ways to read data but better way is to use readFileSync method


/**
 * Created by Anand Dwivedi on 8/25/2016.
 */


var fs=require('fs');

var data=fs.readFileSync('NodeJsSteps.txt');
console.log(data.toString());
console.log('read file Sucessfully');

/**
 var fs=require('fs');

fs.readFile('NodeJsSteps.txt',function (err,data){
   if(err)console.error(err) ;
    console.log(data.toString())
});

 **/

No comments:

Post a Comment