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, …Error with a Node-style code such as ENOENT. See Errors.
Reading and writing
readFile
Uint8Array without an encoding, a string with one.
utf8, latin1, ascii, hex, base64, base64url, utf16le.
writeFile
appendFile
writeFile, but appends, and creates the file when it doesn’t exist.
Files and directories
exists
true when something exists at path.
stat
ENOENT when nothing is there.
mkdir
recursive it also creates missing parents and doesn’t fail when the
directory already exists.
rmdir
recursive it must be empty (ENOTEMPTY).
Other operations
Each has a
*Sync twin.
Watching
watch
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.
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’scode (ENOENT, EEXIST, ENOTEMPTY, …) and the path you passed.