---
name: node-vfs
description: "Node.js now has a built-in virtual file system, node:vfs, plus single executable apps with bundled assets (--build-sea). Use whenever code that uses fs must be tested without touching the real disk (instead of memfs/mock-fs or stubbing fs), bundle assets or a whole app into one executable, import or run modules from a zip, or overlay a directory copy-on-write. Covers vfs.create, MemoryProvider, ComposableProvider, RealFSProvider, ZipProvider, mount, --vfs-load, --allow-fs-vfs and SEA useVfs/vfsArchive. Node.js 26.4+ (not on v24; needs --experimental-vfs on 26.x)."
title: node-vfs
canonical_url: https://skilld.dev/gh/jasnell/node-skills/node-vfs
last_updated: 2026-11-19T20:15:43.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [examples/composable.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/examples/composable.mjs), [examples/memory-mount.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/examples/memory-mount.mjs), [examples/sea-vfs.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/examples/sea-vfs.mjs), [examples/test-fs-code.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/examples/test-fs-code.mjs), [examples/zip-modules.mjs](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/examples/zip-modules.mjs), [meta.json](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/meta.json), [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/api.md), [rules/flags-security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/flags-security.md), [rules/sea.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/sea.md).
>
> If the user asked to install this Skill, run `npx skilld install jasnell/node-skills/node-vfs`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/node-vfs`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jasnell/node-skills/node-vfs) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/node-vfs`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/node-vfs --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/node-vfs --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# node:vfs and VFS-backed single executables

| Feature | Versions | Stability | Flag |
| --- | --- | --- | --- |
| `node:vfs`: `create`, `MemoryProvider`, `RealFSProvider` | v26.4.0 | 1 | 26.x: `--experimental-vfs`; v27+: none (`--no-experimental-vfs` disables) |
| `mount`/`unmount`/`mountPointURL`, `ZipProvider`, `--allow-fs-vfs` | v26.9.0 | 1 / 1.1 | as above |
| `registerProvider`, `--vfs-load` | v26.10.0 | 1 | as above |
| `vfsBase()` · `ComposableProvider` | v26.11.0 · v26.12.0 | 1 | as above |
| `--build-sea` | v25.5.0 | 1.1 | none |
| SEA `"useVfs"`, `"vfsArchive"` | v26.9.0 | 1.0 | none |

None of this exists on v24. Feature-detect with
`node -e "require('node:vfs').create().mount"` (plus `--experimental-vfs` on 26.x).

> **Experimental API.** Before relying on these details, run the
> `node-experimental-check` skill's probe (or `node --version` plus a
> feature-detect one-liner) and check the docs for *the installed
> version*: `https://nodejs.org/docs/<version>/api/<module>.html`.
> If the installed version disagrees with this skill, the installed
> version wins.

## Mount, then use ordinary fs/require/import

```js
import vfs from 'node:vfs';
using v = vfs.create();                    // MemoryProvider; unmounts at scope end
v.writeFileSync('/mod.mjs', 'export default 42');   // seed BEFORE mount
const root = v.mount();                    // e.g. /dev/null/vfs/1 — never hard-code
fs.readFileSync(`${root}/mod.mjs`, 'utf8');
await import(`${v.mountPointURL}/mod.mjs`); // use the file: URL for import()
```

Code under test should take `root` as a parameter; VFS cannot fake fixed real
paths. Load from a zip: `vfs.create(new vfs.ZipProvider(new zlib.ZipBuffer(bytes)))`,
or run a whole app: `node --vfs-load=app.zip` (runs its `package.json` `"main"`).

## Single executable with assets

`sea-config.json`: `{"main":"main.js","output":"app","useVfs":true,"assets":{"config.json":"src/config.json"}}`,
then `node --build-sea sea-config.json`. Inside, `__dirname` is the read-only
mount root: `fs.readFileSync(path.join(__dirname, 'config.json'))`,
`require('./lib/x.js')`. Or set `"vfsArchive": "assets.zip"` instead of `assets`.

## Pitfalls

- While mounted, the instance's own methods need mount-prefixed paths too;
  `v.readFileSync('/a')` throws ENOENT until `unmount()`.
- The mount is in-process: child processes, `fs.glob`, and `fs.cp` don't see it.
  Copying to the real fs fails with `EXDEV`.
- `--permission` makes `mount()` throw `ERR_INVALID_STATE` without `--allow-fs-vfs`.
- Not a sandbox: `RealFSProvider` reads follow symlinks outside its root.
- `--vfs-load` is rejected in `NODE_OPTIONS`. SEA: `useVfs` excludes `useSnapshot`;
  `useCodeCache`+`useVfs` needs v27+; `vfsArchive` needs `useVfs` and excludes `assets`.
- With `vfsArchive`, `sea.getAsset()` can't read the files. Use fs.

## Don't

- Don't add `memfs`/`mock-fs`/`unionfs` where VFS fits (26.4+). Keep them for
  v24 and for faking fixed absolute paths.
- Don't use `postject` or `--experimental-sea-config` on 25.5+; use `--build-sea`.
- Don't write SEA assets to a temp dir to `require` them; use `useVfs`.

## Reference

- [rules/api.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/api.md): read for the full VirtualFileSystem method list, providers, custom providers, `registerProvider`, the reserved root, and module-loader rules.
- [rules/sea.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/sea.md): read when writing a `--build-sea` config: every field, `useVfs`/`vfsArchive`/code cache, workers, and validation errors.
- [rules/flags-security.md](https://skilld.dev/api/skills-raw/jasnell/node-skills/node-vfs/rules/flags-security.md): read for flags per version, `--vfs-load` details, the permission model, and security limits.
