FileTree class

Wraps a file system directory as an async tree

This class wraps the Node.js fs file system API so that you can work with a file system folder as an async tree.

JavaScript usage #

Pass the FileTree constructor a location that’s either a file: URL or a file system path. A relative path will be resolved with respect to the current working directory.

To get a folder relative to the JavaScript module itself, construct a URL relative to import.meta.url.

import { FileTree } from "@weborigami/async-tree";

// Get the tree of files in the "assets" folder next to this module
const files = new FileTree(new URL("assets", import.meta.url));

// Get a stylesheet from the assets folder
const styles = await files.get("styles.css");

API #

new FileTree(location)

  • location: any

async keys()

Returns: Promise<{}>

Enumerate the names of the files/subdirectories in this directory.