-2

How to read the data of a file(say, read.txt) without getting the buffered Data? I mean I want to get the content of the file directly without getting the buffer data? and hoe to delete the folder in Node.js?

  • 1
    It is not clear what you mean. Reading a file returns a buffer. That's what it does. You can convert the buffer to a UTF-8 string if you just want a string representation of the data. – jfriend00 Jan 08 '21 at 07:24
  • Use the [`fs`](https://nodejs.org/dist/latest-v14.x/docs/api/fs.html) module – Marc Jan 08 '21 at 07:45

1 Answers1

0
// Try this //

    fs = require('fs')
    fs.readFile('/read.txt', 'utf8', function (err,data) {
      if (err) {
        return console.log(err);
      }
      console.log(data);
    });
    
    try {
    fs.rmdirSync(dir, { recursive: true });

    console.log(`${dir} is deleted!`);
    }catch (err) {
    console.error(`Error while deleting ${dir}.`);
    }
Sumit Pathak
  • 86
  • 1
  • 2