Index of every page on this site: llms.txt
All skills
jasnell avatar

/node-vfs

@5f83e6c
Run it yourself

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).

Use this Skill: https://skilld.dev/gh/jasnell/node-skills/node-vfs

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

rulessea.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Single executable applications with --build-sea and VFS

Sources: doc/api/single-executable-applications.md and the cli.md --build-sea entry, at nodejs/node ab476eccd03.

Feature Versions Stability
SEA (blob plus postject injection) v19.7.0, v18.16.0 1.1
--build-sea=config: node writes the executable itself v25.5.0 1.1
"useVfs" and "vfsArchive" v26.9.0 1.0
"useCodeCache" together with "useVfs" v27.0.0 (changes entry; rejected on v26.13.0, verified)

v24 has no --build-sea. There, use the older --experimental-sea-config + postject workflow, which is not covered here.

Config (node --build-sea sea-config.json)

{
  "main": "main.js",                 // the injected entry script
  "mainFormat": "commonjs",          // or "module"
  "executable": "/path/to/node",     // optional; defaults to the running node
  "output": "app",                   // Windows: must end in .exe
  "disableExperimentalSEAWarning": true,
  "useSnapshot": false,
  "useCodeCache": false,
  "useVfs": true,
  "vfsArchive": "assets.zip",        // alternative to "assets"
  "execArgv": ["--no-warnings"],
  "execArgvExtension": "env",        // "none" | "env" (default) | "cli"
  "assets": { "config.json": "src/config.json", "lib/add.js": "src/lib/add.js" }
}
  • Relative paths resolve against the cwd, not the config file's directory.
  • The node that builds the blob must match the node that runs it. useCodeCache and useSnapshot must be false for cross-platform builds.
  • macOS needs codesign --sign - app after building. Signing on Windows is optional.
  • execArgvExtension: "none" ignores NODE_OPTIONS. "cli" allows ./app --node-options="--flag".
  • The build took about 3 s on Linux x64 and produced a full copy of the node binary, about 100 MB or more (verified).

Without useVfs

require loads only built-ins. __filename and __dirname come from process.execPath. Read assets with node:sea: getAsset(key[, enc]) (a copy), getAssetAsBlob, getRawAsset (no copy), and getAssetKeys. isSea() reports whether the code runs in a SEA.

With "useVfs": true

  • The assets are mounted read-only, and main runs from the mount root. __dirname is the root, for example /dev/null/vfs/0. Reach files with path.join(__dirname, …), relative require(), and node_modules bundled as assets. Writes fail with EROFS (verified on v26.13.0 and main).
  • With "mainFormat": "module", import.meta.dirname is the mount root, and static and dynamic imports resolve inside it (verified with vfsArchive). require is not defined in an ESM main.
  • sea.getAssetKeys() still lists the assets keys (verified).
  • Worker threads also mount it at the same path, so new Worker(path.join(__dirname, 'worker.js')) works (docs). A VFS you create with vfs.mount() exists only in its own thread.
  • "vfsArchive": "assets.zip" embeds the zip as-is and inflates each file when it is read. Then sea.getAsset() does not serve the files. Build the zip with zlib.zipFiles([[src, name], …]), listing each directory and file explicitly.
  • useCodeCache together with useVfs (v27+) compiles every JS module in the mount at build time.

Validation errors (verified on main)

Config Error
useVfs + useSnapshot "useVfs" is not supported when "useSnapshot" is true
vfsArchive + assets "vfsArchive" cannot be used together with "assets"
vfsArchive without useVfs "vfsArchive" requires "useVfs" to be true
execArgv: ["--vfs-load=…"] --vfs-load cannot be used in "execArgv" … (main only; v26.13.0 accepts it)
useCodeCache + useVfs on v26.13.0 "useVfs" is not supported when "useCodeCache" is true

Native addons

The SEA docs say .node files can't be loaded straight from the SEA VFS. They tell you to write the asset to a temp file and call process.dlopen(). The VFS docs say addons in a mounted VFS load from a private temporary image. Treat it as unverified and test on your target version.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning5d3 checks · Risk SAFE
  • Gen Agent Trust Hub5d

    The skill provides comprehensive documentation and verified examples for the experimental `node:vfs` API and VFS-backed Single Executable Applications (SEA). It correctly identifies security considerations, such as the fact that `RealFSProvider` does not function as a sandbox, and its examples use standard Node.js APIs for feature verification and building binaries in temporary directories.

  • Socket5d

    1 alert: gptAnomaly

  • Snyk5d

    Risk: LOW · No issues

Signed by skilld at 5f83e6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 5 days ago.

Activeupdated last week

README badge

README badge for jasnell/node-skills/node-vfs