fs.readFile()

fs.readFile(file[, options], callback)

Asynchronously reads the entire contents of a file. Example:

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

The callback is passed two arguments (err, data), where data is the contents of the file.

If no encoding is specified, then the raw buffer is returned.

If options is a string, then it specifies the encoding. Example:

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

Any specified file descriptor has to support reading.

Note: Specified file descriptors will not be closed automatically.

doc_Nodejs
2016-04-30 04:39:52
Comments
Leave a Comment

Please login to continue.