• Load a directory tree.

    The function reads the contents of a directory and returns a tree structure of the files and directories. If no options are provided, the function uses the node.js fs/promises module if available. Should this fail, an error is thrown.

    In contrast to the loadDir function, this function attempts to use Node.js's fs/promises module if no options are provided. If the module is not available, an error is thrown.

    Parameters

    • path: PathLike

      The path to the directory. Assumed to be an absolute path.

    • Optionaloptions: LoadOptions<string>

      The options for loading the directory tree.

    Returns Promise<DirectoryTree<string>>

    An error if the fs/promises module is not available.

    // For this example, we'll use the node.js `fs/promises` module anyway.
    import { readFile, readDir } from "fs/promises";

    const tree = await load("path/to/directory", {
    readDir,
    readFile: (path) => readFile(path, "utf8"),