fsPromises.readFile(path[, options])


    Asynchronously reads the entire contents of a file.

    If no encoding is specified (using options.encoding), the data is returned as a <Buffer> 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 of fsPromises.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 an <AbortSignal>. If a request is aborted the promise returned is rejected with an AbortError:

    import { readFile } from 'node:fs/promises';
    try {
      const controller = new AbortController();
      const { signal } = controller;
      const promise = readFile(fileName, { signal });
      // Abort the request before the promise settles.
      await promise;
    } catch (err) {
      // When a request is aborted - err is an AbortError

    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.