INNER CODE UNIT · JavaScript

Promise

Bharat2044/100xDevs-Cohort3-WebDev-and-Devops · Week 02 - Offline Videos/Assignment Solution/Assignment2 Solution/index.js:17

  return new Promise(function (resolve) {
    // reading the file 
    fs.readFile(filePath, "utf-8", function (err, data) {
      // trimming the data from left and right 
      data = data.trim();

      // writing the data back to the file 
      fs.writeFile(filePath, data, function () {
        resolve();
      });
    });
  });
}

// async function to solve the problem statement
async function solve() {
  // calling the cleanFile function with the file path as argument
  await cleanFile("a.txt");

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…