filename or FileHandle
Optional
options: null | { Asynchronously reads the entire contents of a file.
A path to a file. If a URL is provided, it must use the file:
protocol.
If a FileHandle
is provided, the underlying file will not be closed automatically.
An object that may contain an optional flag.
If a flag is not provided, it defaults to 'r'
.
Asynchronously reads the entire contents of a file.
A path to a file. If a URL is provided, it must use the file:
protocol.
If a FileHandle
is provided, the underlying file will not be closed automatically.
Optional
options: null | BufferEncoding | ObjectEncodingOptions & Abortable & { An object that may contain an optional flag.
If a flag is not provided, it defaults to 'r'
.
Asynchronously reads the entire contents of a file.
If no encoding is specified (using
options.encoding
), the data is returned as aBuffer
object. Otherwise, the data will be a string.If
options
is a string, then it specifies the encoding.When the
path
is a directory, the behavior offsPromises.readFile()
is platform-specific. On macOS, Linux, and Windows, the promise will be rejected with an error. On FreeBSD, a representation of the directory's contents will be returned.It is possible to abort an ongoing
readFile
using anAbortSignal
. If a request is aborted the promise returned is rejected with anAbortError
:Aborting an ongoing request does not abort individual operating system requests but rather the internal buffering
fs.readFile
performs.Any specified
FileHandle
has to support reading.Since
v10.0.0
Returns
Fulfills with the contents of the file.