Skip to main content
File I/O shaped like Node’s fs. Every async function has a *Sync twin that blocks until it’s done.
Relative paths start at the script’s data/ folder. Without the filesystem permission everything stays inside it, and paths leading out throw. With it, absolute paths work as usual.

Overview

Reading and writing

readFile, writeFile, appendFile.

Files and directories

exists, stat, mkdir, rmdir, readdir, …

Watching

watch, FSWatcher.

Paths

fs.path.join, basename, …
Failures throw (or reject) an Error with a Node-style code such as ENOENT. See Errors.

Reading and writing

readFile


Reads a whole file: a Uint8Array without an encoding, a string with one.
Encodings: utf8, latin1, ascii, hex, base64, base64url, utf16le.

writeFile


Creates or replaces a file. Strings are written as UTF-8 unless you pass an encoding.

appendFile


Same as writeFile, but appends, and creates the file when it doesn’t exist.

Files and directories

exists


true when something exists at path.

stat


Throws ENOENT when nothing is there.

mkdir


Creates a directory. With recursive it also creates missing parents and doesn’t fail when the directory already exists.

rmdir


Removes a directory. Without recursive it must be empty (ENOTEMPTY).

Other operations

Each has a *Sync twin.

Watching

watch


Calls listener for every change: "rename" for created, deleted or renamed entries, "change" for modified ones. filename is relative to the watched path, and can be null.
A listener that throws doesn’t stop the watcher. Watchers close on unload, or earlier with close(), using or an aborted signal.

Paths

fs.path has the common helpers of Node’s path (Windows flavour). String work only, no I/O.

Errors

Errors carry Node’s code (ENOENT, EEXIST, ENOTEMPTY, …) and the path you passed.

Example

A JSON settings file that reloads when you edit it.