Skip to content

File System Adapter

Access files from your local filesystem. Don't be confused by the node in the package name, it should also work with bun as it is node compatible, but there are plans to make a more bun specific adapter. For now, you should use this for bun as well, as all adapters are interchangeable, you can easily switch to the bun specific adapter later if you want to.

sh
npm add @loom-io/node-filesystem-adapter
sh
pnpm add @loom-io/node-filesystem-adapter
sh
bun add @loom-io/node-filesystem-adapter

Setup and configuration

As a parameter, you can set the context where the adapter should interact. By default, this is the project directory. You can't go any lower than that.

ts
import FilesystemAdapter from "@loom-io/node-filesystem-adapter";

const root = new FilesystemAdapter("/");
const project = new FilesystemAdapter();
const rootDir = root.dir("/");
const projectDir = project("/");

Additional functionality

getFullPath

By default, the root of each file is set to the current working directory or the specified installation path, and the path returned by the directory of the file object is a relative path to that directory. If the full path is needed, it can be generated by calling adapter.getFullPath(dirOrFileObject). By default this function checks if it is from the same adapter and throws an error if not. Set the second param of the function to true to not check the adapter and ignore the path if it probably does not exist.