node file system require('fs). This function readFile() once finished passed the data that it has read to a callBack function which is error first callback function

PHOTO EMBED

Tue Aug 31 2021 01:29:35 GMT+0000 (Coordinated Universal Time)

Saved by @faisals #node #filesystem

const fs = require('fs');
 
let readDataCallback = (err, data) => {
  if (err) {
    console.log(`Something went wrong: ${err}`);
  } else {
    console.log(`Provided file contained: ${data}`);
  }
};
 
fs.readFile('./file.txt', 'utf-8', readDataCallback);
content_copyCOPY

Each method available through the fs module has a synchronous version and an asynchronous version. One method available on the fs core module is the .readFile() method which reads data from a provided file: