Method description:
Read file contents asynchronously.
Without top content encoding, it will be output in buffer format, such as: <Buffer 32 33 31 32 33 31 32 33 31 32 33>
grammar:
The code copy is as follows:
fs.readFile(filename, [encoding], [callback(err,data)])
Since this method belongs to the FS module, it is necessary to introduce the FS module before use (var fs= require("fs") )
Receive parameters:
filename file path
options option object, including encoding, encoding format, this item is optional.
callback callback, passing 2 parameters exception err and file content data
example:
The code copy is as follows:
var fs = require('fs');
fs.readFile('content.txt','utf-8', function(err,data){
if(err){
console.log(err);
}else{
console.log(data);
}
})