Skip to content

Comments

Add synchronous node:fs support for Durable Objects#2

Merged
danlapid merged 1 commit intomainfrom
dlapid/syncfs
Feb 14, 2026
Merged

Add synchronous node:fs support for Durable Objects#2
danlapid merged 1 commit intomainfrom
dlapid/syncfs

Conversation

@danlapid
Copy link
Owner

@danlapid danlapid commented Jan 29, 2026

Adds Phase 1 of sync filesystem support, enabling synchronous node:fs methods inside Durable Objects via LocalDOFilesystem.

Key changes:

  • Add SyncWorkerFilesystem interface with sync methods (*Sync variants)
  • Create LocalDOFilesystem that operates directly on ctx.storage.sql
  • Unify mount API: single mount() accepts both async and sync filesystems
  • Add fs-sync.ts as drop-in replacement for node:fs (via wrangler alias)
  • Async fs methods automatically fall back to sync when available
  • Add 18 new tests for sync operations and async-to-sync fallback
  • Add sync-do-fs example demonstrating the feature
  • Update documentation with correct patterns

Usage in Durable Object:

import { DurableObject } from 'cloudflare:workers'; import { mount } from 'worker-fs-mount';
import { LocalDOFilesystem } from 'durable-object-fs'; import fs from 'node:fs';

export class MyDO extends DurableObject {
    constructor(ctx, env) {
        super(ctx, env);
        mount('/data', new LocalDOFilesystem(ctx.storage.sql));
    }
    fetch() {
        fs.writeFileSync('/data/file.txt', 'hello');
        return new Response(fs.readFileSync('/data/file.txt', 'utf8'));
    }
}

wrangler.toml alias:

[alias]
"node:fs" = "worker-fs-mount/fs-sync"

Adds Phase 1 of sync filesystem support, enabling synchronous node:fs
methods inside Durable Objects via LocalDOFilesystem.

Key changes:
- Add SyncWorkerFilesystem interface with sync methods (*Sync variants)
- Create LocalDOFilesystem that operates directly on ctx.storage.sql
- Unify mount API: single mount() accepts both async and sync filesystems
- Add fs-sync.ts as drop-in replacement for node:fs (via wrangler alias)
- Async fs methods automatically fall back to sync when available
- Add 18 new tests for sync operations and async-to-sync fallback
- Add sync-do-fs example demonstrating the feature
- Update documentation with correct patterns

Usage in Durable Object:
import { DurableObject } from 'cloudflare:workers';
import { mount } from 'worker-fs-mount';
import { LocalDOFilesystem } from 'durable-object-fs';
import fs from 'node:fs';

export class MyDO extends DurableObject {
    constructor(ctx, env) {
        super(ctx, env);
        mount('/data', new LocalDOFilesystem(ctx.storage.sql));
    }
    fetch() {
        fs.writeFileSync('/data/file.txt', 'hello');
        return new Response(fs.readFileSync('/data/file.txt', 'utf8'));
    }
}

wrangler.toml alias:
[alias]
"node:fs" = "worker-fs-mount/fs-sync"
@danlapid danlapid merged commit 262de55 into main Feb 14, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant