fs

native module

Filesystem I/O. import "fs". Fallible; follows the (value, err) convention.

fs.read(path: string) => (string, string?)

Read a whole file as a string.

fs.write(path: string, content: string) => string?

Write content, replacing existing contents.

fs.append(path: string, content: string) => string?

Append content, creating the file if needed.

fs.exists(path: string) => bool

Whether a path exists (predicate).

fs.remove(path: string) => string?

Delete a file or directory.

fs.rename(old: string, new: string) => string?

Rename/move a path.

fs.mkdir(path: string) => string?

Create a directory.

fs.readdir(path: string) => ([string], string?)

Entry names directly inside a directory.

fs.is_dir(path: string) => bool

Whether path is a directory (predicate).

fs.size(path: string) => (int, string?)

File size in bytes.

fs.read_lines(path: string) => ([string], string?)

Read a file split into lines.

fs.walk(dir: string) => ([string], string?)

Full paths of every regular file under dir, recursively.

fs.glob(pattern: string) => ([string], string?)

Paths matching a shell glob (*, ?, [..]).

On this page