Answers for "how to import fs readfile"

7

nodejs readfile

const fs = require('fs');

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err);
    return
  }
  console.log(data);
});
Posted by: Guest on August-30-2020
0

how to export fs.readFile

var fs = require('fs');

module.exports = {
    parseFile: function(file_path, callback) {
        fs.readFile(file_path.toString(), 'utf-8', function(err, data) {
            if (err) return callback(err);
            callback(null, data);
        });
    }
}

// much shorter version
exports.parseFile = function(file_path, callback) {
    fs.readFile(file_path.toString(), 'utf-8', callback);
}
Posted by: Guest on November-19-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language