“fs.readfile” Kode Jawaban

NodeJS ReadFile

const fs = require('fs');

fs.readFile('/Users/joe/test.txt', 'utf8' , (err, data) => {
  if (err) {
    console.error(err);
    return
  }
  console.log(data);
});
Light Locust

NodeJS ReadFile

const fs = require('fs')

try {
  const data = fs.readFileSync('/Users/joe/test.txt', 'utf8')
  console.log(data)
} catch (err) {
  console.error(err)
}
Ofir Salem

JavaScript FS dibaca

fs.readFile('/etc/passwd', (err, data) => {
  if (err) throw err;
  console.log(data);
});
Repulsive Reindeer

fs.readfile

fs.readFile('filename', function read(err, data) {
    if (err) {
        throw err;
    }
    var content = data;
  
    console.log(content);  
   
});
If-dev

cara mengekspor 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);
}
Bad Bat

FS ReadFile Encoding

fs.readFile('/etc/passwd', 'utf8', callback);
The little dog

Jawaban yang mirip dengan “fs.readfile”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya