Skip to content

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

2 participants