Add worker-fs-mount docs to node:fs page#28432
Add worker-fs-mount docs to node:fs page#28432ask-bonk[bot] wants to merge 2 commits intoproductionfrom
Conversation
Co-authored-by: irvinebroque <irvinebroque@users.noreply.github.com>
|
This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:
|
irvinebroque
left a comment
There was a problem hiding this comment.
/bonk please revise these docs with my feedback, that the docs need to explain the pattern that worker-fs-mount implements, but shouldn't link directly or tell people to depend on it. The purpose of these docs should be to help a human or agent understand how they could implement this on their own. Since the docs here on fs are long, it may make sense to break this out into a tutorial or example, separately in the docs, so that there is space to go into enough detail.
|
|
||
| ## Mount persistent storage with worker-fs-mount | ||
|
|
||
| The built-in virtual file system is ephemeral — `/tmp` is cleared between requests, and `/bundle` is read-only. If you need persistent, durable file storage accessible through the standard `node:fs` API, you can use the [`worker-fs-mount`](https://github.com/danlapid/worker-fs-mount) package to mount Cloudflare storage services (such as [R2](/r2/) or [Durable Objects](/durable-objects/)) as virtual file system paths. |
There was a problem hiding this comment.
This should not link direct to that project or treat it like it is a package to depend on
|
|
||
| The built-in virtual file system is ephemeral — `/tmp` is cleared between requests, and `/bundle` is read-only. If you need persistent, durable file storage accessible through the standard `node:fs` API, you can use the [`worker-fs-mount`](https://github.com/danlapid/worker-fs-mount) package to mount Cloudflare storage services (such as [R2](/r2/) or [Durable Objects](/durable-objects/)) as virtual file system paths. | ||
|
|
||
| This approach works like a Unix mount point: you choose a path (for example, `/storage`), associate it with a storage backend, and then use standard `node:fs` APIs like `readFile`, `writeFile`, `mkdir`, and `stat` against that path. The `worker-fs-mount` package intercepts calls to `node:fs` and routes them to the appropriate storage backend based on the path prefix. Paths that do not match any mount fall through to the built-in virtual file system. |
There was a problem hiding this comment.
We shouldnt reference Unix mount points, people reading dont know what that is
|
/bonk please revise these docs with my feedback, that the docs need to explain the pattern that worker-fs-mount implements, but shouldn't link directly or tell people to depend on it. The purpose of these docs should be to help a human or agent understand how they could implement this on their own. Since the docs here on fs are long, it may make sense to break this out into a tutorial or example, separately in the docs, so that there is space to go into enough detail. |
Revise fs.mdx to remove direct references to worker-fs-mount package and Unix mount terminology per reviewer feedback. The persistent storage section now briefly explains the pattern and links to a new tutorial. Create standalone tutorial that teaches how to build a custom node:fs shim using Wrangler module aliasing, including the storage backend interface, mount registry, fs shim, R2 implementation, and AsyncLocalStorage-based request isolation.
|
All done. Here is a summary of the changes: Changes made1. Revised
|
irvinebroque
left a comment
There was a problem hiding this comment.
@danlapid WDYT about having a guide like this that unpacks how you can implement https://github.com/danlapid/worker-fs-mount
Here is a summary of the changes made to
src/content/docs/workers/runtime-apis/nodejs/fs.mdx:What changed
New content: "Mount persistent storage with worker-fs-mount" section
The existing
node:fsdocs only covered the built-in ephemeral virtual file system (/bundle,/tmp,/dev). Theworker-fs-mountrepository demonstrates a significant pattern — mounting Cloudflare storage services as virtual filesystem paths accessible through standardnode:fsAPIs — that was entirely undocumented. The new section covers:How it works — Explains the Wrangler module aliasing mechanism that intercepts
node:fsimports and routes operations to storage backends based on path prefixes.Installation and Wrangler configuration — Step-by-step setup including the critical
[alias]configuration and thenode:prefix requirement to avoid alias loops.Mount an R2 bucket — Complete example showing module-scope mounting of R2 with
WranglerConfigand a working code sample.Mount a Durable Object — Example using
withMounts()for request-scoped mounting withAsyncLocalStorageisolation, important because DO stubs require I/O to obtain.Synchronous access inside Durable Objects — Pattern for using
LocalDOFilesystemwithreadFileSync/writeFileSyncdirectly inside a DO, accessing SQLite storage synchronously.Supported operations table — Full reference of which
node:fsmethods work on mounted paths (both async and sync variants).Mount rules — Constraints on mount paths (absolute paths, reserved paths, no nesting).
Storage backends comparison — Collapsible table comparing R2, Durable Object (remote and local), and in-memory backends.
Pre-existing content improvements
compatibility_date = "$today"to allWranglerConfigblocksCloses #28431
github run