Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

node:fs

ImportsImplementation
node:fs, node:fs/promises@bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/fs

By default, node:fs and node:fs/promises use one jco:node/fs@0.1.0 host capability. When either specifier occurs in bundled source, Jco adds a missing import to the selected world, installs fs.wit under deps/jco-node-0.1.0, and prints a CLI warning to alert to the fact that a WIT dependency has been added.

The default filesystem host provider returns a typed denial result, which the guest reconstructs as ERR_JCO_FS_ADAPTER_REQUIRED. To use the passthrough NodeJS host provider you can map it in:

jco transpile component.wasm \
  --map 'jco:node/fs@0.1.0=@bytecodealliance/jco-std/wasi/0.2.x/node/24.x.x/fs/host/node'

To use a WASI Preview 2 host, build with --bundle --with-nodejs-vfs-via wasi-filesystem. Jco bundles the filesystem provider into the guest. Both modules share one descriptor table and resolve paths against the host’s preopened directories. Relative paths use the guest’s initial working directory, falling back to / when it is unspecified. See the Wasmtime example.

The WASI provider supports file reads, writes, directory operations, links and metadata. Use cp and rm for recursive copy and removal, glob for pattern matching, and mkdtemp to create a temporary directory. The host sets permissions on newly created files and directories, including temporary directories. WASI 0.2.12 exposes no way to change file permissions or ownership or query filesystem-wide statistics, so chmod, chown and statfs are unavailable.

The direct Node provider uses the following call path.

  1. guest node:fs
  2. WIT capability
  3. host adapter
  4. NodeJS builtins

The Node provider delegates to Node 24’s synchronous operations; guest callback APIs queue their callbacks on a microtask, and promise APIs share the same descriptor state through promise FileHandles.

Common file and directory operations, metadata, directory entries, scalar and vector descriptor I/O, and their callback/promise facades are supported.

Warning

APIs whose contract requires long-lived streams or event sources are not yet supported – including ReadStream, WriteStream, Utf8Stream, watch, watchFile, and openAsBlob.

These functions currently throw ERR_JCO_UNSUPPORTED_NODE_API because the typed WIT interface does not model those resources.